在iPhone上测试应用程序时出错,但在模拟器中没有错误

时间:2011-09-12 13:44:24

标签: iphone ios xcode ios-simulator

我在iPhone上测试应用程序时遇到以下错误,但模拟器中没有出现错误。当我加载我的rootViewController这是一个UITableView时。我对iOS编程比较陌生,我只是想知道是否有人可以对它有所了解! 问候, 迈克尔。 使用此代码转到我的RootView。

- (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'

2 个答案:

答案 0 :(得分:1)

您的错误是index 0 beyond bounds for empty array错误。在您访问数组的行上放置断点。当您找出导致问题的阵列时,解决方案将是微不足道的,或者您可以在问题中添加更多内容并寻求进一步的帮助。

答案 1 :(得分:0)

看起来问题出现在[RootViewController tableView:numberOfRowsInSection:]的实现中。您正在尝试访问一个空的NSMutableArray成员 - 因此错误'index 0超出了空数组的边界'。