我寫了這個代碼,當我運行它,它trows例外:無法識別的選擇發送到實例0xba3e750目標C:無法識別的選擇發送到實例0xba3e750
storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
navigationController = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewID"];
selected = navigationController.viewControllers[0];
,當我把這個線在評論
//selected = navigationController.viewControllers[0];
那樣,程序不會拋出異常。 這是孔例外
2014-06-12 20:59:44.749 passing image[2194:a0b] -[SecondViewController viewControllers]: unrecognized selector sent to instance 0xba3e750
2014年6月12日20:59:44.753傳遞圖像[2194:A0B] *終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因:「 - [SecondViewController viewControllers]:無法識別的選擇發送到實例0xba3e750' *第一擲調用堆棧: ( 0的CoreFoundation 0x017445e4 exceptionPreprocess + 180 1 libobjc.A.dylib 0x014c78b6 objc_exception_throw + 44 2的CoreFoundation 0x017e1903 - [NSObject的(NSObject的)doesNotRecognizeSelector:] + 275 3的CoreFoundation 0x0173490b ___forwarding_ + 1019 4的CoreFoundation 0x017344ee _CF_forwarding_prep_0 + 14 5通過圖像0x000056a2 - [視圖控制器viewDidLoad中] + 466 6的UIKit 0x00349318 - [UIViewController中loadViewIfRequired] + 696 7的UIKit 0x003495b4 - [UIViewController的視圖] + 35 8 UIKit的0x002719fd - [一個UIWindow addRootViewControllerViewIfPossible] + 66 9的UIKit 0x00271d97 - [一個UIWindow _setHidden:強制:] + 312 10的UIKit 0x0027202d - [一個UIWindow _orderFrontWithoutMakingKey] + 49 11的UIKit 0x0027c89a - [一個UIWindow makeKeyAndVisible] + 65 12的UIKit 0x0022fcd0 - [UIApplication _callInitializationDelegates ForURL:有效載荷:懸浮:] + 1851 13的UIKit 0x002343a8 - [UIApplication的_runWithURL:有效載荷:launchOrientation:statusBarStyle:statusBarHidden:] + 824 14的UIKit 0x0024887c - [UIApplication的的handleEvent:withNewEvent:] + 3447 15的UIKit 0x00248de9 - [UIApplication的的SendEvent:] + 85 16的UIKit 0x00236025 _UIApplicationHandleEvent + 736個 17 GraphicsServices 0x037932f6 _PurpleEventCallback + 776 18 GraphicsServices 0x03792e01 PurpleEventCallback + 46 19的CoreFoundation 0x016bfd65 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 53 20的CoreFoundation 0x016bfa9b __CFRunLoopDoSource1 + 523 21 CoreFoundatio Ñ0x016ea77c __CFRunLoopRun + 2156 22的CoreFoundation 0x016e9ac3 CFRunLoopRunSpecific + 467 23的CoreFoundation 0x016e98db CFRunLoopRunInMode + 123 24的UIKit 0x00233add - [UIApplication的_run] + 840 25的UIKit 0x00235d3b UIApplicationMain + 1225 26傳遞圖像0x0000750d主+ 141 27 libdyld.dylib 0x01e78725開始+ 0 28 00000001爲0x0 + 1 ) 的libC++ abi.dylib:與類型的未捕獲的異常NSException (LLDB)
可以請你從控制檯添加了整個錯誤消息。 – lootsch
我已經添加了它 –
看來,您的ViewController「SecondViewController」不是「UINavigationController」。 – lootsch