开发者

NSMutableArray only good for 25 items

开发者 https://www.devze.com 2023-03-26 14:49 出处:网络
I have an NSMutableArray which I use with UITableView. The strange issue I am facing is that [results removeObjectAtIndex:rowIndexPath.row];

I have an NSMutableArray which I use with UITableView. The strange issue I am facing is that

[results removeObjectAtIndex:rowIndexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:rowIndexPath] withRowAnimation:开发者_如何学CUITableViewRowAnimationFade];

only works for the first 25 elements of the table, but crashes on the 26th? Nowhere in my code do I have any mention of 25 and I am at a loss why it does this.

All the elements display properly via UITableView so they have been inserted properly in the table.

Any help?


Odds are that as you remove items from the index, you aren't reloading your table, so the rowIndexPath.row value isn't adjusted properly and you therefore run over the size of your array.


Just a guess:

With removeObjectAtIndex:(NSUInteger)index, you can see in documentation: To fill the gap, all elements beyond index are moved by subtracting 1 from their index. so you collapse elements, you can't iterate over the count of the array without updating the length, otherwise you will try to read an invalid index just because list collapsed by previous removes and it is shorter compared to what you expected.

0

精彩评论

暂无评论...
验证码 换一张
取 消