【问题标题】:Navigation one view controller to another getting将一个视图控制器导航到另一个视图控制器
【发布时间】:2016-09-06 17:24:53
【问题描述】:

我想将 viewController 导航到 TargetViewController,但出现以下错误:

2016-05-11 15:47:27.182 数字总和[2882:209790] *** 终止 应用程序由于未捕获的异常“NSUnknownKeyException”,原因: '[setValue:forUndefinedKey:]: 此类与键 bttn 的键值编码不兼容。'

*** 第一次抛出调用堆栈:( 0 CoreFoundation 0x00000001016f9f45 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000101173deb objc_exception_throw + 48 2 核心基础
0x00000001016f9b89 -[NSException raise] + 9 3 基础
0x0000000100d40a6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x0000000101c3104c -[UIViewController setValue:forKey:] + 88 5 UIKit 0x0000000101e5ea71 -[UIRuntimeOutletConnection 连接] + 109 6
核心基础 0x000000010163aa80 -[NSArray makeObjectsPerformSelector:] + 224 7 UIKit
0x0000000101e5d454 -[UINib instantiateWithOwner:options:] + 1864 8
UIKit 0x0000000101c37c16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x0000000101c38542 -[UIViewController loadView] + 178 10 UIKit
0x0000000101c388a0 -[UIViewController loadViewIfRequired] + 138 11 UIKit 0x0000000101c39013 -[UIViewController 视图] + 27 12 UIKit 0x00000001023db7e7 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87 13 UIKit 0x0000000101c08dde -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133 14 UIKit 0x0000000101c4b9ba -[UIViewController _presentViewController:withAnimationController:completion:] + 4004 15 UIKit 0x0000000101c4ec5c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 489 16 UIKit 0x0000000101c4e76b -[UIViewController presentViewController:animated:completion:] + 179 17 数字之和 0x0000000100c756f8 -[ViewController 总和:] + 120 18 UIKit 0x0000000101aa7e91 -[UIApplication sendAction:to:from:forEvent:] + 92 19 UIKit 0x0000000101c134d8 -[UIControl sendAction:to:forEvent:] + 67 20 UIKit 0x0000000101c137a4 -[UIControl_sendActionsForEvents:withEvent:] + 311 21 UIKit 0x0000000101c128d4 -[UIControl touchesEnded:withEvent:] + 601 22 UIKit 0x0000000101b15ed1 -[UIWindow _sendTouchesForEvent:] + 835 23 UIKit 0x0000000101b16c06 -[UIWindow sendEvent:] + 865 24 UIKit
0x0000000101ac62fa -[UIApplication sendEvent:] + 263 25 UIKit
0x0000000101aa0abf _UIApplicationHandleEventQueue + 6844 26 核心基础 0x0000000101626011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 27 核心基础 0x000000010161bf3c __CFRunLoopDoSources0 + 556 28 CoreFoundation 0x000000010161b3f3 __CFRunLoopRun + 867 29 CoreFoundation
0x000000010161ae08 CFRunLoopRunSpecific + 488 30 图形服务
0x0000000104e95ad2 GSEventRunModal + 161 31 UIKit
0x0000000101aa630d UIApplicationMain + 171 32 数字之和
0x0000000100c75aaf 主 + 111 33 libdyld.dylib
0x0000000103e1d92d 开始 + 1 ) libc++abi.dylib: 终止于 NSException (lldb) 类型的未捕获异常

我的 viewController.m

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)Sum:(id)sender {
    TargetViewController *add = [[TargetViewController alloc]
                                  initWithNibName:@"TargetViewController123" bundle:nil];

   // TargetViewController *membr = [[TargetViewController alloc] initWithNibName:@"TargetViewController123"];

    [self presentViewController:add animated:YES completion:nil];
}
@end

我不知道我在哪里得到错误。请帮忙

【问题讨论】:

  • 请编辑您的问题并将错误日志和您的代码都放在代码块中,以便阅读。因为现在的格式很糟糕。
  • 右键单击视图控制器的黄色按钮,在情节提要中检查您的插座。

标签: ios


【解决方案1】:

此处描述了您的错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key bttn.

这意味着有东西试图在一个没有同名属性的类上调用属性bttn。如果您在视图控制器中连接了 IBOutlet,然后在代码中将其删除但忘记从 Interface Builder 中的元素中删除出口引用,则通常会发生这种情况。

【讨论】:

  • 太棒了。如果解决方案正确,您可以考虑接受答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-12
  • 1970-01-01
  • 1970-01-01
  • 2014-07-25
  • 2020-10-04
  • 1970-01-01
相关资源
最近更新 更多