This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(69个答案)
2年前关闭。
我使用此代码:
在我午餐应用程序后,我的应用程序崩溃了:
我认为崩溃的原因是此行:
另外,我
该插件:DropDown
代码:
您已从代码中删除了该行,但是
此类与键optionLabel的键值编码不兼容。
若要解决此问题,请按照下列步骤操作:
(69个答案)
2年前关闭。
我使用此代码:
let amountDropDown = DropDown()
amountDropDown.anchorView = view
amountDropDown.dataSource = ["Car", "Motorcycle", "Truck"]
在我午餐应用程序后,我的应用程序崩溃了:
2018-05-12 17:45:18.946508+0430 Matap[47483:593732] Unknown class _TtC13DropDown_Demo12DropDownCell in Interface Builder file.
2018-05-12 17:45:18.965499+0430 Matap[47483:593732] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x7f9001d38760> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key optionLabel.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e19612b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010d82af41 objc_exception_throw + 48
2 CoreFoundation 0x000000010e196079 -[NSException raise] + 9
3 Foundation 0x000000010d249a63 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010f097288 -[UIView(CALayerDelegate) setValue:forKey:] + 172
5 UIKit 0x000000010f457c2d -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010e1393cd -[NSArray makeObjectsPerformSelector:] + 317
7 UIKit 0x000000010f4565e3 -[UINib instantiateWithOwner:options:] + 1856
8 Matap 0x000000010cea3e51 _T08DropDownAAC12fittingWidth33_7BE2DBF176694C4708972467648CE159LL12CoreGraphics7CGFloatVyF + 785
9 Matap 0x000000010cea67e8 _T08DropDownAAC39constraintWidthToFittingSizeIfNecessary33_7BE2DBF176694C4708972467648CE159LLy12CoreGraphics7CGFloatV1x_AG1yAG5widthAG15offscreenHeighttz6layout_tF + 216
10 Matap 0x000000010cea2d3b _T08DropDownAAC13computeLayout33_7BE2DBF176694C4708972467648CE159LL12CoreGraphics7CGFloatV1x_AG1yAG5widthAG15offscreenHeightAG07visibleN0Sb14canBeDisplayedAB9DirectionOANtyF + 2651
11 Matap 0x000000010cea08e7 _T08DropDownAAC17updateConstraintsyyF + 215
12 Matap 0x000000010cea3554 _T08DropDownAAC17updateConstraintsyyFTo + 36
13 UIKit 0x000000010fb46878 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 161
14 UIKit 0x000000010fb46e94 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1296
15 UIKit 0x000000010fb476c5 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 90
16 UIKit 0x000000010fb47234 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160
17 Matap 0x000000010ce9fa6b _T08DropDownAAC5setup33_7BE2DBF176694C4708972467648CE159LLyyFyycfU_ + 43
18 Matap 0x000000010ceb10d2 _T08DropDownAAC5setup33_7BE2DBF176694C4708972467648CE159LLyyFyycfU_TA + 50
19 Matap 0x000000010ce6e2c9 _T0Ix_IyB_TR + 41
20 libdispatch.dylib 0x0000000112ff12f7 _dispatch_call_block_and_release + 12
21 libdispatch.dylib 0x0000000112ff233d _dispatch_client_callout + 8
22 libdispatch.dylib 0x0000000112ffd5f9 _dispatch_main_queue_callback_4CF + 628
23 CoreFoundation 0x000000010e158e39 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
24 CoreFoundation 0x000000010e11d462 __CFRunLoopRun + 2402
25 CoreFoundation 0x000000010e11c889 CFRunLoopRunSpecific + 409
26 GraphicsServices 0x000000011538b9c6 GSEventRunModal + 62
27 UIKit 0x000000010efc65d6 UIApplicationMain + 159
28 Matap 0x000000010ce83fa7 main + 55
29 libdyld.dylib 0x000000011306ed81 start + 1
30 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我认为崩溃的原因是此行:
let amountDropDown = DropDown()
另外,我
import DropDown
进入我的快速代码该插件:DropDown
代码:
import UIKit
import DropDown
class ViewControllerHandle: UIViewController {
@IBOutlet var viewMain: UIView!
@IBOutlet weak var backBoard: UIView!
@IBOutlet weak var secondGo: UIView!
@IBOutlet weak var thirdGo: UIView!
@IBOutlet weak var firstGo: UIView!
@IBOutlet weak var goToSecond: UIView!
@IBOutlet weak var firstView: UIView!
/* BOX GENDER */
@IBOutlet weak var boxGender: UIView!
@IBOutlet weak var genderSelect: UIView!
@IBOutlet weak var pickerGender: UIPickerView!
@IBOutlet weak var textPickerGender: UILabel!
/* BOX EX */
@IBOutlet weak var boxEx: UIView!
@IBOutlet weak var exSelect: UIView!
/* BOX EMERGENCY */
@IBOutlet weak var boxEmergency: UIView!
@IBOutlet weak var emergencySelect: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let backBoardGesture = UITapGestureRecognizer(target: self, action: #selector(handleBackBoard(sender:)))
backBoard.addGestureRecognizer(backBoardGesture)
let goToSecondGesture = UITapGestureRecognizer(target: self, action: #selector(handleGoToSecond(sender:)))
goToSecond.addGestureRecognizer(goToSecondGesture)
let setBG = SetBackground()
setBG.addGradient(viewMain: viewMain)
secondGo.layer.cornerRadius = 45
thirdGo.layer.cornerRadius = 45
firstGo.layer.cornerRadius = 45
goToSecond.layer.cornerRadius = 20
boxGender.layer.cornerRadius = 25
genderSelect.layer.cornerRadius = 20
boxEx.layer.cornerRadius = 25
exSelect.layer.cornerRadius = 20
boxEmergency.layer.cornerRadius = 25
emergencySelect.layer.cornerRadius = 20
let amountDropDown = DropDown()
}
@objc func handleGoToSecond(sender: UITapGestureRecognizer) {
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "ViewControllerMenu")
self.present(homeViewController, animated: true, completion: nil)
}
@objc func handleBackBoard(sender: UITapGestureRecognizer) {
dismiss(animated: true, completion: nil)
}
}
最佳答案
您的视图控制器文件中的出口为UILabel
。如:
@IBOutlet weak var optionLabel: UILabel!
您已从代码中删除了该行,但是
UIStoryboard
上仍然提供了引用,这就是为什么会收到错误:此类与键optionLabel的键值编码不兼容。
若要解决此问题,请按照下列步骤操作:
关于ios - Swift:如果使用DropDown(),则崩溃的应用程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50314324/
10-13 03:48