当用户向下滚动 UITableView,经过最后一个单元格时,为什么我的应用程序会退出?

发布于 2024-12-13 05:52:43 字数 1646 浏览 1 评论 0原文

当用户向下滚动 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢好甜 2024-12-20 05:52:43

您的一个数组是空的,您正在尝试从中获取第一个元素。确保此逻辑在 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionUITableView 调用之前运行,以便它可以返回正确的计数。

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 the UITableView so that it can return the correct count.

贪了杯 2024-12-20 05:52:43

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文