我的應用程序的更新需要一個設置,用戶可以選擇加載哪個視圖。 因此,因爲我使用故事板,我設法創建一個視圖控制器,通過故事板連接到另一個視圖,充當「根視圖控制器」根視圖控制器 - 重定向到特定視圖拋出異常
然後,我將下面的代碼添加到該視圖,在這裏使用一個示例字符串來測試代碼是否工作。
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *test = @"one";
id rootController;
if (test == @"one") {
rootController = [self.storyboard instantiateViewControllerWithIdentifier:@"one"];
} else if (test == @"two") {
rootController = [self.storyboard instantiateViewControllerWithIdentifier:@"two"];
}
else if (test == @"three") {
rootController = [self.storyboard instantiateViewControllerWithIdentifier:@"three"];
}
else {
rootController = [self.storyboard instantiateViewControllerWithIdentifier:@"none"];
}
self.view = [NSArray arrayWithObjects:rootController, nil];
}
但每當啓動應用以下異常拋出了:
2012-11-23 16:30:40.482 MyApp[1587:c07] -[__NSArrayI _setViewDelegate:]: unrecognized selector sent to instance 0x716cf30
2012-11-23 16:30:40.501 MyApp[1587:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI _setViewDelegate:]: unrecognized selector sent to instance 0x716cf30'
*** First throw call stack:
(0x1c8e012 0x10cbe7e 0x1d194bd 0x1c7dbbc 0x1c7d94e 0xf85ac 0xf4a90 0x2dee 0xf4817 0xf4882 0xf4b2a 0x10bef5 0x10bfdb 0x10c286 0x10c381 0x10ceab 0x10cfc9 0x10d055 0x2123ab 0x6392d 0x10df6b0 0x228afc0 0x227f33c 0x228aeaf 0x1028cd 0x4b1a6 0x49cbf 0x49bd9 0x48e34 0x48c6e 0x49a29 0x4c922 0xf6fec 0x43bc4 0x43dbf 0x43f55 0x4cf67 0x10fcc 0x11fab 0x23315 0x2424b 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x117da 0x1365c 0x21dd 0x2105)
libc++abi.dylib: terminate called throwing an exception
爲什麼不工作的代碼?
按照控制檯日誌烏爾調用是不可用的方法.. – vishy
目前尚不清楚你的故事板中所設定的是。該行:self.view = [NSArray arrayWithObjects:rootController,nil];沒有任何意義 - 你將視圖設置爲一個數組。我不確定你想用這條線做什麼。 – rdelmar