将一个视图控制器导航到另一个视图控制器

时间:2016-05-11 10:51:35

标签: ios

我想将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 CoreFoundation
  0x00000001016f9b89 - [NSException raise] + 9 3基础
  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视图] + 27 12 UIKit 0x00000001023db7e7 - [_ UIFullscreenPresentationController   _setPresentedViewController:] + 87 13 UIKit 0x0000000101c08dde - [UIPresentationController   initWithPresentedViewController:presentsViewController:] + 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 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图形服务
  0x0000000104e95ad2 GSEventRunModal + 161 31 UIKit
  0x0000000101aa630d UIApplicationMain + 171 32数字之和
  0x0000000100c75aaf main + 111 33 libdyld.dylib
  0x0000000103e1d92d start + 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

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

1 个答案:

答案 0 :(得分:5)

您的错误在此处描述:

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中的元素中删除插座引用,则通常会发生这种情况。