NSRangeException',原因:'*** – :索引0超出界限为空数组'当呈现视图控制器

我开发了一个应用程序,在testing中工作正常,但是当它可以生活时,我已经有一些与崩溃时出现模态视图控制器的问题。 这个问题在这里有些地方:

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]; 

谁能帮忙?

检查mtaViewController中的任何数组,我没有看到你的代码中的任何数组,所以我想这个问题是在mtaViewController。 🙂

你确定你的视图控制器真的被初始化? 只是一个想法,但这条线

 [mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 

如果mtaViewController是零将不会做任何事情。 在cocoa,你可以发送消息没有问题。 你的应用程序只会在你尝试做某些特定的事情时才会崩溃。 是否

 NSLog(@"%@", mtaViewController); 

告诉你有用的东西? 请确保您连接了必须连接的IB的所有内容(如果您不是以原始代码工作)。

顺便一提。 这已被弃用。 使用

 presentViewController:animated:completion: 

代替。