开发者

Update UITableViewCell without reload

So here's my situation:

I have a UITableView where each cell has some buttons.

In the cellForRowAtIndexPath I set the indexpath of the row so when the a button is clicked I know what row was clicked.

One of the buttons is a delete button and when pressed I remove the backing data and delete the row from the table.

The problem I'm having is that after I delete a row the indexPath's of the other rows are incorrect as the other rows have not been redrawn. The only way I can find to r开发者_StackOverflowedraw the table is to call reload but this messes up the animation.

I figure this kind of problem must have been addressed before. Does anyone have any suggestions on how to get around this? I'm ok with changing the way I've designed my buttons to work if there is a better way.


Think you need to use this...

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

Apple reference!


You should be able to redraw the tableview without a full reload by starting and ending an update like this:

[tableView beginUpdates];
[tableView endUpdates];


call the method: - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation


It is better not to store the indexPath with the buttons. In the button action handler (which is either a method in your cell subclass or in your viewController) you could identify the cell, and subsequently determine the indexPath using -indexPathForCell:.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜