4

私はテストで正常に機能するアプリを開発しましたが、それが機能する可能性がある場合、モーダルビューコントローラーを表示するとクラッシュする問題が発生しました。問題はここのどこかにあります:

NSLog(@"Looks like we made it here 1");

UIViewController *mtaViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"mtaViewController"];
NSLog(@"Looks like we made it here 2");

[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
NSLog(@"Looks like we made it here 3");

[self presentModalViewController:mtaViewController animated:YES]; 
NSLog(@"Looks like we made it here 4");

コンソールへの出力は次のとおりです。

2012-06-14 09:26:24.161 appname[2013:707] Looks like we made it here 1
2012-06-14 09:26:24.165 appname[2013:707] Looks like we made it here 2
2012-06-14 09:26:24.166 appname[2013:707] Looks like we made it here 3
2012-06-14 09:26:28.866 appname[2013:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x343ac8bf 0x345fc1e5 0x342f5b6b 0x6d3fd 0x6e719 0x3778e7ff 0x37798d53 0x37798cc1 0x37838339 0x3783714f 0x37891d97 0x7ce1d 0x7cd47 0x3788eaa5 0x3776a81b 0x3776ffb9 0x34ec1ba7 0x36fe0e8d 0x3437f2dd 0x343024dd 0x343023a5 0x30b86fcd 0x37783743 0x84327 0x6b468)
terminate called throwing an exception

ビューコントローラを変更したいときに呼び出す関数を設定しましたが、ご覧のとおり「ここで作成したようです3」になっているので、行に問題があるのではないかと思います。

[self presentModalViewController:mtaViewController animated:YES];

誰か助けてもらえますか?

4

2 に答える 2

1

ビューコントローラが実際に初期化されますか?ただのアイデアですが、この行

[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

mtaViewControllerがnilの場合、何もしません。Cocoaでは、問題なくnilにメッセージを送信できます。アプリは、後で特定のことを行おうとしたときにのみクラッシュします。しますか

NSLog(@"%@", mtaViewController);

何か役に立つことを教えてください。また、接続する必要のあるすべてをIBで接続していることを確認してください(生のコードですべてを処理していない場合)。

ところで。これは非推奨です。使用する

presentViewController:animated:completion:

代わりは。

于 2012-06-14T08:42:12.913 に答える
1

mtaViewControllerの配列を確認してください。コードに配列が表示されないため、問題はmtaViewController内にあると考えています。:)

于 2012-06-14T08:43:31.523 に答える