1

我在基于导航的应用程序中有四个视图。MainView、AddView、ShowView 和 DetailView。MainView 有一个 NSMutableArray。当我单击按钮添加时,我转到 AddView,然后在 MainView 的 NSMutable 数组中添加一个对象。然后我回来并转到 ShowView,它是一个 tableView。从 MainView 我调用 ShowView 的 createList 函数,如下所示:

 ShowView *show = [[ShowView alloc] init];
    [show createList: self.savedObjectsList];
    [self.navigationController pushViewController: show animated: YES];

    [runListController release]; 

在 ShowView createList 中看起来像这样:

 - (void) createRunsList: (NSMutableArray *) list{
     objList = [list retain];

 }

其中 objList 是 ShowView 中的 NSMutableArray。表格视图的每个单元格都会创建 NSMutbaleArray 对象的 DetailView。问题是有时我的应用程序停止工作并且我收到此错误:

 2011-10-03 15:35:55.076 RunnoIPhoneApp[2750: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                      0x3399964f __exceptionPreprocess + 114
1   libobjc.A.dylib                     0x30b16c5d objc_exception_throw + 24
2   CoreFoundation                      0x33904069 -[__NSArrayM objectAtIndex:] + 184
3   RunnoIPhoneApp                      0x0000b79f -[PostRunDetailViewController createRunDetail:] + 90
4   RunnoIPhoneApp                      0x0000fd2f -[RunListViewController tableView:didSelectRowAtIndexPath:] + 182
5   UIKit                               0x3203f51b -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 662
6   UIKit                               0x320a30eb -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 130
7   Foundation                          0x32ba26d5 __NSFireDelayedPerform + 368
8   CoreFoundation                      0x33970a47 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
9   CoreFoundation                      0x33972ecb __CFRunLoopDoTimer + 850
10  CoreFoundation                      0x33973845 __CFRunLoopRun + 1088
11  CoreFoundation                      0x33903ec3 CFRunLoopRunSpecific + 230
12  CoreFoundation                      0x33903dcb CFRunLoopRunInMode + 58
13  GraphicsServices                    0x3162e41f GSEventRunModal + 114
14  GraphicsServices                    0x3162e4cb GSEventRun + 62
15  UIKit                               0x32019d69 -[UIApplication _run] + 404
16  UIKit                               0x32017807 UIApplicationMain + 670
17  RunnoIPhoneApp                      0x00002553 main + 70
18  RunnoIPhoneApp                      0x00002508 start + 40
 )
 terminate called after throwing an instance of 'NSException'
 Program received signal:  “SIGABRT”.
 warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.5 (8L1)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
 Program received signal:  “SIGABRT”.
 (gdb) 

谁能告诉我为什么会这样?一些第一个对象的 DetailView 工作正常,但随后我收到此错误。提前致谢。

4

2 回答 2

1

查看堆栈跟踪,在您的 [PostRunDetailViewController createRunDetail:] 方法中引发了异常,当您在 RunListViewController 的 UITableView 中选择一行时会调用该方法。您正在尝试访问数组中超出范围的元素。

在此方法的开头放置一个断点,并在调试器中单步执行。找出导致异常的数组访问,然后思考为什么数组可能不包含您期望的元素。

于 2011-10-03T14:26:04.257 回答
0

只需评论这一行 [runListController release];

于 2011-10-03T15:33:31.187 回答