Ios 应用程序正在崩溃,出现错误:“0”;此类不符合key tableView的键值编码;。如何修复?
我有10个连接的UIButtons,在buttonPressed iAction中有不同的标签,我的segue的ID为“GoToDetailVC” 然后我想用标记中的数字替换headerLabel文本Ios 应用程序正在崩溃,出现错误:“0”;此类不符合key tableView的键值编码;。如何修复?,ios,xcode,swift3,Ios,Xcode,Swift3,我有10个连接的UIButtons,在buttonPressed iAction中有不同的标签,我的segue的ID为“GoToDetailVC” 然后我想用标记中的数字替换headerLabel文本 import UIKit class DetailVC: UIViewController { @IBOutlet weak var headerLabel: UILabel! private var _buttonNumber: Int! var buttonNumber: Int {
import UIKit
class DetailVC: UIViewController {
@IBOutlet weak var headerLabel: UILabel!
private var _buttonNumber: Int!
var buttonNumber: Int {
get {
return _buttonNumber
} set {
_buttonNumber = newValue
}
}
override func viewDidLoad() {
super.viewDidLoad()
headerLabel.text = "\(_buttonNumber!)"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func dismissView(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
}
它正在崩溃并产生此消息
2016-12-31 12:36:36.439 Core Geometry[2638:539019] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Core_Geometry.DetailVC 0x7fc55251aea0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108a67d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010615b21e objc_exception_throw + 48
2 CoreFoundation 0x0000000108a67c99 -[NSException raise] + 9
3 Foundation 0x0000000105c699df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x00000001067be293 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x0000000106a3279e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x0000000108a0c9e0 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x0000000106a31122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x00000001067c49c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x00000001067c52e7 -[UIViewController loadView] + 177
10 UIKit 0x00000001067c561c -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x00000001067c5e70 -[UIViewController view] + 27
12 UIKit 0x00000001070866a4 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
13 UIKit 0x00000001067a0702 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141
14 UIKit 0x00000001067d8e97 -[UIViewController _presentViewController:withAnimationController:completion:] + 3956
15 UIKit 0x00000001067dc26b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
16 UIKit 0x00000001067dbd51 -[UIViewController presentViewController:animated:completion:] + 179
17 UIKit 0x0000000106de9717 __74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 133
18 UIKit 0x0000000106df91dd -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 447
19 UIKit 0x0000000106df8fed -[UIStoryboardSegueTemplate _perform:] + 82
20 UIKit 0x00000001067c8a1f -[UIViewController performSegueWithIdentifier:sender:] + 99
21 Core Geometry 0x00000001056c6de1 _TFC13Core_Geometry6MainVC13buttonPressedfT6senderPs9AnyObject__T_ + 465
22 Core Geometry 0x00000001056c6f86 _TToFC13Core_Geometry6MainVC13buttonPressedfT6senderPs9AnyObject__T_ + 54
23 UIKit 0x00000001066258bc -[UIApplication sendAction:to:from:forEvent:] + 83
24 UIKit 0x00000001067abc38 -[UIControl sendAction:to:forEvent:] + 67
25 UIKit 0x00000001067abf51 -[UIControl _sendActionsForEvents:withEvent:] + 444
26 UIKit 0x00000001067aae4d -[UIControl touchesEnded:withEvent:] + 668
27 UIKit 0x0000000106693545 -[UIWindow _sendTouchesForEvent:] + 2747
28 UIKit 0x0000000106694c33 -[UIWindow sendEvent:] + 4011
29 UIKit 0x00000001066419ab -[UIApplication sendEvent:] + 371
30 UIKit 0x0000000106e2e72d __dispatchPreprocessedEventFromEventQueue + 3248
31 UIKit 0x0000000106e27463 __handleEventQueue + 4879
32 CoreFoundation 0x0000000108a0c761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
33 CoreFoundation 0x00000001089f198c __CFRunLoopDoSources0 + 556
34 CoreFoundation 0x00000001089f0e76 __CFRunLoopRun + 918
35 CoreFoundation 0x00000001089f0884 CFRunLoopRunSpecific + 420
36 GraphicsServices 0x000000010a965a6f GSEventRunModal + 161
37 UIKit 0x0000000106623c68 UIApplicationMain + 159
38 Core Geometry 0x00000001056c654f main + 111
39 libdyld.dylib 0x0000000105b8768d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
2016-12-31 12:36:36.439核心几何[2638:539019]***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合key tableView的键值编码。”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x0000000108a67d4b例外预处理+171
1 libobjc.A.dylib 0x000000010615b21e objc_异常_抛出+48
2 CoreFoundation 0x0000000108a67c99-[N异常上升]+9
3基金会0x000 000 0105C699 DF- [ NSO对象(NSKEY ValueCoDIN)SETValue:FordK::] + 291
4 UIKit 0x00000001067be293-[UIViewController设置值:forKey:+88
5 UIKit 0x0000000106a3279e-[UIRuntimeOutletConnection connect]+109
6 CoreFoundation 0x0000000108a0c9e0-[NSArray makeObjectsPerformSelector:+256
7 UIKit 0x0000000106a31122-[UINib实例化所有者:选项:][1867
8 UIKit 0x00000001067c49c5-[UIViewController\u loadViewFromNibNamed:bundle:][386
9 UIKit 0x00000001067c52e7-[UIViewController loadView]+177
10 UIKit 0x00000001067c561c-[UIViewController loadViewIfRequired]+201
11 UIKit 0x00000001067c5e70-[UIViewController视图]+27
12 UIKit 0x00000001070866a4-[\u UIFullScreen显示控制器\u setPresentedViewController:+87
13 UIKit 0x00000001067a0702-[UIPresentationController初始化带PresentedViewController:presentingViewController:+141
14 UIKit 0x00000001067d8e97-[UIViewController\u presentViewController:withAnimationController:completion:+3956
15 UIKit 0x00000001067dc26b-[UIViewController\u性能协调演示文稿:动画:][530
16 UIKit 0x00000001067dbd51-[UIViewController当前视图控制器:动画:完成:][179
17 UIKit 0x0000000106de9717 uu 74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:][u block_invoke+133
18 UIKit 0x0000000106df91dd-[UIStoryboardSegueTemplate]性能与目标视图控制器:发送方:][447
19 UIKit 0x0000000106df8fed-[UIStoryboardSegueTemplate]执行:+82
20 UIKit 0x00000001067c8a1f-[UIViewController性能设置,标识符为:发送方:][99
21堆芯几何图形0x00000001056c6de1\u TFC13堆芯几何图形6主VC13按钮按下DFT6发送器9任何对象
22堆芯几何图形0x00000001056c6f86\u TTOFC13堆芯几何图形6主VC13按钮按下DFT6发送器9任何对象
23 UIKit 0x00000001066258bc-[UIApplication sendAction:to:from:forEvent:][83
24 UIKit 0x00000001067abc38-[UIControl发送操作:发送到:forEvent:+67
25 UIKit 0x00000001067abf51-[UIControl\u发送操作预防:带事件:][444
26 UIKit 0x00000001067aae4d-[UIControl触摸附加:withEvent:][668
27 UIKit 0x0000000106693545-[UIWindow\u sendTouchesForEvent:+2747
28 UIKit 0x0000000106694c33-[UIWindow sendEvent:+4011
29 UIKit 0x00000001066419ab-[UIApplication sendEvent:+371
30 UIKit 0x0000000106e2e72d uu调度预处理事件RomeventQueue+3248
31 UIKit 0x0000000106e27463_u handleEventQueue+4879
32 CoreFoundation 0x0000000108a0c761\uuuuu CFRUNLOOP\u正在调用\uu OUT\u以执行\uu函数\uuuuu+17
33 CoreFoundation 0x00000001089f198c\uu CFRunLoopDoSources0+556
34 CoreFoundation 0x00000001089f0e76\uuu CFRunLoopRun+918
35 CoreFoundation 0x00000001089f0884 CFRunLoopRunSpecific+420
36图形服务0x000000010a965a6f GSEventRunModal+161
37 UIKit 0x0000000106623c68 UIApplicationMain+159
38堆芯几何形状0x00000001056c654f主+111
39 libdyld.dylib 0x0000000105b8768d启动+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)
显然,您的nib文件中有问题。首先尝试删除表视图
和其他视图之间的所有连接。这意味着所有插座(IBOutlet
)和操作(IBAction
)。很有可能坠机事件会过去。之后,您可以再次尝试重新连接插座和操作,但请确保操作正确。原因错误表明您正在使用tableView
连接到一个类,但它没有名为tableView
的键(属性)。因此,您可能试图与错误的类/对象建立连接。请在控制台中发布您收到的完整错误,并发布代码,而不是代码的屏幕截图。请检查您的segue连接。我认为(从错误中)它连接不正确
2016-12-31 12:36:36.439 Core Geometry[2638:539019] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Core_Geometry.DetailVC 0x7fc55251aea0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108a67d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010615b21e objc_exception_throw + 48
2 CoreFoundation 0x0000000108a67c99 -[NSException raise] + 9
3 Foundation 0x0000000105c699df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x00000001067be293 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x0000000106a3279e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x0000000108a0c9e0 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x0000000106a31122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x00000001067c49c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x00000001067c52e7 -[UIViewController loadView] + 177
10 UIKit 0x00000001067c561c -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x00000001067c5e70 -[UIViewController view] + 27
12 UIKit 0x00000001070866a4 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
13 UIKit 0x00000001067a0702 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141
14 UIKit 0x00000001067d8e97 -[UIViewController _presentViewController:withAnimationController:completion:] + 3956
15 UIKit 0x00000001067dc26b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
16 UIKit 0x00000001067dbd51 -[UIViewController presentViewController:animated:completion:] + 179
17 UIKit 0x0000000106de9717 __74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 133
18 UIKit 0x0000000106df91dd -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 447
19 UIKit 0x0000000106df8fed -[UIStoryboardSegueTemplate _perform:] + 82
20 UIKit 0x00000001067c8a1f -[UIViewController performSegueWithIdentifier:sender:] + 99
21 Core Geometry 0x00000001056c6de1 _TFC13Core_Geometry6MainVC13buttonPressedfT6senderPs9AnyObject__T_ + 465
22 Core Geometry 0x00000001056c6f86 _TToFC13Core_Geometry6MainVC13buttonPressedfT6senderPs9AnyObject__T_ + 54
23 UIKit 0x00000001066258bc -[UIApplication sendAction:to:from:forEvent:] + 83
24 UIKit 0x00000001067abc38 -[UIControl sendAction:to:forEvent:] + 67
25 UIKit 0x00000001067abf51 -[UIControl _sendActionsForEvents:withEvent:] + 444
26 UIKit 0x00000001067aae4d -[UIControl touchesEnded:withEvent:] + 668
27 UIKit 0x0000000106693545 -[UIWindow _sendTouchesForEvent:] + 2747
28 UIKit 0x0000000106694c33 -[UIWindow sendEvent:] + 4011
29 UIKit 0x00000001066419ab -[UIApplication sendEvent:] + 371
30 UIKit 0x0000000106e2e72d __dispatchPreprocessedEventFromEventQueue + 3248
31 UIKit 0x0000000106e27463 __handleEventQueue + 4879
32 CoreFoundation 0x0000000108a0c761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
33 CoreFoundation 0x00000001089f198c __CFRunLoopDoSources0 + 556
34 CoreFoundation 0x00000001089f0e76 __CFRunLoopRun + 918
35 CoreFoundation 0x00000001089f0884 CFRunLoopRunSpecific + 420
36 GraphicsServices 0x000000010a965a6f GSEventRunModal + 161
37 UIKit 0x0000000106623c68 UIApplicationMain + 159
38 Core Geometry 0x00000001056c654f main + 111
39 libdyld.dylib 0x0000000105b8768d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)