ios - 将一个 View Controller 导航到另一个 View Controller

标签 ios

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

2016-05-11 15:47:27.182 Sum of Numbers[2882:209790] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key bttn.'

*** First throw call stack: ( 0 CoreFoundation 0x00000001016f9f45 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000101173deb objc_exception_throw + 48 2 CoreFoundation
0x00000001016f9b89 -[NSException raise] + 9 3 Foundation
0x0000000100d40a6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x0000000101c3104c -[UIViewController setValue:forKey:] + 88 5 UIKit 0x0000000101e5ea71 -[UIRuntimeOutletConnection connect] + 109 6
CoreFoundation 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 view] + 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 Sum of Numbers 0x0000000100c756f8 -[ViewController Sum:] + 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 CoreFoundation 0x0000000101626011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 27 CoreFoundation 0x000000010161bf3c __CFRunLoopDoSources0 + 556 28 CoreFoundation 0x000000010161b3f3 __CFRunLoopRun + 867 29 CoreFoundation
0x000000010161ae08 CFRunLoopRunSpecific + 488 30 GraphicsServices
0x0000000104e95ad2 GSEventRunModal + 161 31 UIKit
0x0000000101aa630d UIApplicationMain + 171 32 Sum of Numbers
0x0000000100c75aaf main + 111 33 libdyld.dylib
0x0000000103e1d92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type 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

我不知道哪里出错了。请帮忙

最佳答案

此处描述了您的错误:

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

这意味着某些东西正在尝试调用一个类上的属性 bttn,但该类没有此名称的属性。如果您在 View Controller 中连接了一个 IBOutlet,然后在代码中将其删除但忘记从 Interface Builder 中的元素中删除 socket 引用,则经常会发生这种情况。

关于ios - 将一个 View Controller 导航到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37160448/

相关文章:

ios - XCTest 在 UITest 中全新安装应用程序

ios - 在 iOS 11 中的 whatsapp 上分享带标题的图片

ios - Xcode 8 没有警告将 NSString 分配给 NSInteger?

objective-c - 查看首次安装的应用程序版本 - iOS

ios - Flutter:在 iOS 和 Android 中禁用滑动导航返回

iphone - 尝试由不同的类加载时 TableView 崩溃

ios - UIView animateWithDuration 返回原始状态

ios - 当用户遇到错误或与 XMPP 断开连接时重新连接 XMPP

ios - 将 UITableViewDataSource 与具有 subview 的自定义单元格一起使用

ios - 作为 iOS 框架一部分的 Metal 文件