私のアプリのアップデートには、ユーザーがロードするビューを選択できるセットアップが必要です。ストーリーボードを使用しているので、ストーリーボードを介して「ルートビューコントローラー」として機能する別のビューに接続されたビューコントローラーを作成することができました。
次に、そのビューに次のコードを追加しました。ここでは、サンプル文字列を使用して、コードが機能するかどうかをテストしています。
- (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
コードが機能しないのはなぜですか?