当用户向下滚动 UITableView,经过最后一个单元格时,为什么我的应用程序会退出?
当用户向下滚动 UITableView、经过第一个/最后一个单元格时,为什么我的应用程序会退出?
这是我的日志:
2011-11-02 07:53:23.794 School VLE Business[20876:707] *** Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x30bfa8bf 0x37d9f1e5 0x30b43b6b 0x51493 0x32bf49cb 0x32bf3a09 0x32bf3233 0x32b97d4b 0x30b5922b 0x322ad381 0x322acf99
0x322b111b 0x322b0e57 0x322d86f1 0x322fb4c5 0x322fb379 0x358e0f93 0x31e8e891 0x30bc3f43 0x30bce553 0x30bce4f5 0x30bcd343
0x30b504dd 0x30b503a5 0x3377efed 0x32bc2743 0x2645 0x25dc)
terminate called throwing an exception[Switching to process 7171 thread 0x1c03]
(gdb)
请记住,这是我用来向 UITableView 添加/删除对象的代码:
maincelltext = [[NSMutableArray alloc] init];
subtitlecelltext = [[NSMutableArray alloc] init];
if(maincelltext.count == 0){
[maincelltext addObject:@"No Dates Set"];
[subtitlecelltext addObject:@"Try adding a note!"];
}
if(Assignment1DueDate.text.length > 1){
[maincelltext addObject:Assignment1.text];
[subtitlecelltext addObject:Assignment1DueDate.text];
}
if(Assignment2DueDate.text.length > 1){
[maincelltext addObject:Assignment2.text];
[subtitlecelltext addObject:Assignment2DueDate.text];
}
if(Assignment3DueDate.text.length > 1){
[maincelltext addObject:Assignment3.text];
[subtitlecelltext addObject:Assignment3DueDate.text];
}
if(Assignment4DueDate.text.length > 1){
[maincelltext addObject:Assignment4.text];
[subtitlecelltext addObject:Assignment4DueDate.text];
}
...等等...
Why does my app quit when user scrolls down the UITableView, past the first/last cell?
Here is my log:
2011-11-02 07:53:23.794 School VLE Business[20876:707] *** Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x30bfa8bf 0x37d9f1e5 0x30b43b6b 0x51493 0x32bf49cb 0x32bf3a09 0x32bf3233 0x32b97d4b 0x30b5922b 0x322ad381 0x322acf99
0x322b111b 0x322b0e57 0x322d86f1 0x322fb4c5 0x322fb379 0x358e0f93 0x31e8e891 0x30bc3f43 0x30bce553 0x30bce4f5 0x30bcd343
0x30b504dd 0x30b503a5 0x3377efed 0x32bc2743 0x2645 0x25dc)
terminate called throwing an exception[Switching to process 7171 thread 0x1c03]
(gdb)
Bear in mind that this is the code I use to add/remove objects to/from the UITableView:
maincelltext = [[NSMutableArray alloc] init];
subtitlecelltext = [[NSMutableArray alloc] init];
if(maincelltext.count == 0){
[maincelltext addObject:@"No Dates Set"];
[subtitlecelltext addObject:@"Try adding a note!"];
}
if(Assignment1DueDate.text.length > 1){
[maincelltext addObject:Assignment1.text];
[subtitlecelltext addObject:Assignment1DueDate.text];
}
if(Assignment2DueDate.text.length > 1){
[maincelltext addObject:Assignment2.text];
[subtitlecelltext addObject:Assignment2DueDate.text];
}
if(Assignment3DueDate.text.length > 1){
[maincelltext addObject:Assignment3.text];
[subtitlecelltext addObject:Assignment3DueDate.text];
}
if(Assignment4DueDate.text.length > 1){
[maincelltext addObject:Assignment4.text];
[subtitlecelltext addObject:Assignment4DueDate.text];
}
... and so on...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的一个数组是空的,您正在尝试从中获取第一个元素。确保此逻辑在
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
被UITableView
调用之前运行,以便它可以返回正确的计数。One of your arrays is empty and you are trying to get the first element out of it. Make sure this logic runs before
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
is called by theUITableView
so that it can return the correct count.当 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 调用 UITAbleView 数据源的委托方法时,向 UITableView 提供数据的 NSArray 未初始化或为 null。在设置 UITableView 的数据源之前,请确保要在 UITableView 中添加的数据已添加到 NSArray(您的数据数组)中。
Your NSArray which feeds data into UITableView is not initialised or null at the time -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section , a delegate method of UITAbleView data source is called.Make sure that the data which you want to add in UITableView is added in NSArray (your data array) before you set the dataSource of UITableView.