简体   繁体   中英

Why does my app quit when user scrolls down the UITableView, past the last cell?

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

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.

你的数据输入到UITableView的NSArray当时没有初始化或为null - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)部分 ,调用UITAbleView数据源的委托方法。确保你的数据是哪个想要添加UITableView是在设置UITableView的dataSource之前在NSArray(您的数据数组)中添加的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM