2012-06-14 139 views
3

我開發了一個應用程序,在測試中工作正常,但是當它可以生活我有在展示模態視圖控制器時遇到了一些崩潰問題。問題是在這裏的一些地方:NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:索引0超出空數組的界限'當呈現視圖控制器

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

誰能幫助?

回答

1

檢查mtaViewController中的任何數組,我沒有看到你的代碼中的任何數組,所以我想這個問題是在mtaViewController。 :)

+0

這絕對有可能。但是也可能出現這種情況,這個數組只是他們的工程師知道的Apple私有實現的一部分。 – pbx

+0

謝謝。我仍然在學習目標c,這是我最初的想法,我沒有與故事板一起工作。 :) – TheNitram

1

您確定您已查看控制器真的嗎被初始化?只是一個想法,但這條線

[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 

如果mtaViewController將是零。在Cocoa中,你可以毫無問題地發送消息給零。你的應用程序只有在你嘗試做某些特定的事情時纔會崩潰。

NSLog(@"%@", mtaViewController); 

告訴你一些有用的東西?請確保您連接了必須連接的IB的所有內容(如果您沒有使用原始代碼工作)。

順便說一句。這已被棄用。使用

presentViewController:animated:completion: 

改爲。

+0

感謝您的幫助,我改變了這一點,但它不是錯誤。我實際上已經發現它現在正在破壞的位置,它沒有任何意義,它應該在測試中崩潰,但事實並非如此。 – Popeye

+0

錯誤究竟是什麼?上面的代碼其他所有代碼似乎都沒問題。 – pbx

+0

基本上,當運行thisModalViewController時,它會在mtaViewController上加載viewDidLoad,該數組中有一個數組,它被搞亂了。但它應該在測試中完成同樣的事情,所以我對它有點困惑。 – Popeye

相關問題