2011-09-12 24 views
0

當我在iPhone上測試我的應用程序時,出現以下錯誤,但該錯誤不會在模擬器中發生。當我加載我的rootViewController這是一個UITableView。我對iOS編程相對來說比較陌生,我只是想知道是否有人能夠闡明它! 關心, 邁克爾。 使用此代碼去我的RootView。在iPhone上測試應用程序時出錯,但在模擬器中沒有錯誤

- (IBAction)goToRootView { 
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
[self.navigationController pushViewController:rootViewController animated:YES]; 
[rootViewController release]; 

}

2011-09-12 14:39:55.951 LeagueProject[773:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array' 
    *** Call stack at first throw: 
    (
     0 CoreFoundation      0x3684b64f __exceptionPreprocess + 114 
     1 libobjc.A.dylib      0x33aa4c5d objc_exception_throw + 24 
     2 CoreFoundation      0x367b6069 -[__NSArrayM objectAtIndex:] + 184 
     3 LeagueProject      0x0000302f -[RootViewController tableView:numberOfRowsInSection:] + 58 
     4 UIKit        0x356827c7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1338 
     5 UIKit        0x356836bb -[UITableViewRowData rectForFooterInSection:] + 66 
     6 UIKit        0x356835f5 -[UITableViewRowData heightForTable] + 40 
     7 UIKit        0x35683453 -[UITableView(_UITableViewPrivate) _updateContentSize] + 206 
     8 UIKit        0x3567ebc9 -[UITableView _rectChangedWithNewSize:oldSize:] + 384 
     9 UIKit        0x3567d833 -[UITableView setFrame:] + 158 
     10 UIKit        0x35684e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 274 
     11 UIKit        0x356510bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 120 
     12 UIKit        0x356364e9 -[UIView(Geometry) setFrame:] + 336 
     13 UIKit        0x35688193 -[UIViewControllerWrapperView setFrame:] + 62 
     14 UIKit        0x35676079 -[UINavigationController _startTransition:fromViewController:toViewController:] + 960 
     15 UIKit        0x35675c43 -[UINavigationController _startDeferredTransitionIfNeeded] + 182 
     16 UIKit        0x35667d5d -[UINavigationController pushViewController:transition:forceImmediate:] + 640 
     17 UIKit        0x35667ad3 -[UINavigationController pushViewController:animated:] + 34 
     18 LeagueProject      0x0000917d -[splashView goToRootView] + 116 
     19 CoreFoundation      0x367bb571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24 
     20 UIKit        0x3564dec9 -[UIApplication sendAction:to:from:forEvent:] + 84 
     21 UIKit        0x3564de69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32 
     22 UIKit        0x3564de3b -[UIControl sendAction:to:forEvent:] + 38 
     23 UIKit        0x3564db8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356 
     24 UIKit        0x3564e423 -[UIControl touchesEnded:withEvent:] + 342 
     25 UIKit        0x3564cbf5 -[UIWindow _sendTouchesForEvent:] + 368 
     26 UIKit        0x3564c56f -[UIWindow sendEvent:] + 262 
     27 UIKit        0x35635313 -[UIApplication sendEvent:] + 298 
     28 UIKit        0x35634c53 _UIApplicationHandleEvent + 5090 
     29 GraphicsServices     0x35f6fe77 PurpleEventCallback + 666 
     30 CoreFoundation      0x36822a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26 
     31 CoreFoundation      0x3682483f __CFRunLoopDoSource1 + 166 
     32 CoreFoundation      0x3682560d __CFRunLoopRun + 520 
     33 CoreFoundation      0x367b5ec3 CFRunLoopRunSpecific + 230 
     34 CoreFoundation      0x367b5dcb CFRunLoopRunInMode + 58 
     35 GraphicsServices     0x35f6f41f GSEventRunModal + 114 
     36 GraphicsServices     0x35f6f4cb GSEventRun + 62 
     37 UIKit        0x3565fd69 -[UIApplication _run] + 404 
     38 UIKit        0x3565d807 UIApplicationMain + 670 
     39 LeagueProject      0x000025a7 main + 82 
     40 LeagueProject      0x00002550 start + 40 
    ) 
    terminate called after throwing an instance of 'NSException' 
+1

更仔細地閱讀崩潰日誌 - tableView中有錯誤:numberOfRowsInSection:RootViewController的方法 - 你應該在那裏尋找可能的問題 – Vladimir

+2

什麼版本的iOS是你的模擬器。你正在創建的應用程序的版本是什麼版本(屬性下的基礎SDK版本)?最後,您的設備上的iOS版本是什麼? – ApolloSoftware

+0

還要確保它沒有在Xcode中的下拉菜單中說「iOS設備」,它應該說出設備的名稱。 – ApolloSoftware

回答

1

你的錯誤是一個index 0 beyond bounds for empty array錯誤。在您訪問數組的行上放置斷點。當您發現哪個陣列導致問題時,解決方案將變得微不足道,或者您可以在問題中添加更多內容並要求獲得進一步的幫助。

+0

感謝您的回覆。我在等待答案的同時查看了一下,並且NSLog記錄了一些從互聯網上下載的數據,這些數據成爲數組內容。我使用了正則表達式和東西來查找我想要的維基百科文章的一部分,並且編輯部分的代碼已經從編輯的時間段中消失了,因爲編輯的時間已經結束了(信息是一個季節的一部分,昨晚結束)。所以今天早上我改變了它沒有[編輯],但iPhone仍然看到[編輯]。也許瀏覽的差異?不確定! –

+0

從您無法控制的網站讀取信息通常不是一個好主意,因爲您無法保證網站的格式。他們不僅可能會通過不同的服務器/瀏覽器等出現差異,作者可能會在明天做徹底的檢修! 我會建議尋找一個維基百科API,但我不知道這樣的事情是否存在。 –

+0

是的我暫時使用維基百科信息,應該在未來幾周內訪問該網站,但由於時間問題,我需要展示我到目前爲止所做的工作。感謝幫助雖然人,會看看我是否可以解決這個問題! –

0

看起來問題出在您的[RootViewController tableView:numberOfRowsInSection:]的實現中。您試圖訪問空的NSMutableArray的成員 - 因此錯誤「索引0超出空數組的界限」。

相關問題