Iphone nsrange异常';,原因:';***-[u NSArrayM objectAtIndex:]:索引0超出空数组的界限';显示视图控制器时

Iphone nsrange异常';,原因:';***-[u NSArrayM objectAtIndex:]:索引0超出空数组的界限';显示视图控制器时,iphone,objective-c,ios,Iphone,Objective C,Ios,我开发了一个应用程序,在测试中运行良好,但当它可以运行时,我在演示模态视图控制器时遇到了一些崩溃问题。问题就在这里: NSLog(@"Looks like we made it here 1"); UIViewController *mtaViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"mtaViewController"]; NSLog(@"Looks like we made it he

我开发了一个应用程序,在测试中运行良好,但当它可以运行时,我在演示模态视图控制器时遇到了一些崩溃问题。问题就在这里:

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”,所以我怀疑line存在问题

[self presentModalViewController:mtaViewController animated:YES];

有人能帮忙吗?

你确定你查看的控制器真的初始化了吗?只是一个想法,但这行

[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
如果mtaViewController为零,则不会执行任何操作。在Cocoa中,您可以毫无问题地向nil发送消息。您的应用程序只有在您尝试对其执行特定操作时才会崩溃。做

NSLog(@"%@", mtaViewController);
告诉你一些有用的事情?还请确保您连接了IB中必须连接的所有内容(如果您没有在原始代码中解决所有问题)

顺便说一下。这是不赞成的。使用

presentViewController:animated:completion:

相反。

检查mtaViewController中的任何数组,我在代码中看不到任何数组,因此我认为问题出在mtaViewController中。:)

这是绝对可能的。但也可能是这样的,这个阵列是苹果私有实现的一部分,只有他们的工程师知道。谢谢。我仍在学习目标c,这是我最初的想法,我不使用故事板谢谢你的帮助,我已经改变了,但这不是错误。事实上,我已经发现它现在在哪里崩溃了,它在测试中应该崩溃是没有意义的,但它没有。到底是什么错误?上面代码的其他一切似乎都正常。基本上,当运行当前的ModalViewController时,它会在mtaViewController上加载viewDidLoad,该控制器中有一个混乱的数组。但它应该在测试中做同样的事情,所以我有点困惑。