开发者

UITableViewCell's disappear after insertion/deletion

开发者 https://www.devze.com 2023-04-01 16:52 出处:网络
I have a few UITableView\'s in my project, and sometimes I need to swap cells between them. Cells are complex enough and it\'s take a lot of time to re-create them each time I move them from one table

I have a few UITableView's in my project, and sometimes I need to swap cells between them. Cells are complex enough and it's take a lot of time to re-create them each time I move them from one table to another, so I create its once, keep in array and pick up necessary cells  in cellForRowAtIndexPath Moving cells between tables looks 开发者_如何学编程something like this:

NSIndexPath* pathForMovedCell = [firstTableView indexPathForCell:movedCell];
[firstTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:pathForMovedCell] withRowAnimation:UITableViewRowAnimationFade];
//There is some delay for show animation and switch between view controllers
[secondTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:pathForMovedCell] withRowAnimation:UITableViewRowAnimationFade];

This code works pretty good, but sometimes (always, if delay less then 0,33 seconds) cell is not drawn on secondTableView. It normally inserted, and will be drawn if scroll them from visible area and return back. I think it's happens if inserting occurs before deletion animation ends. If I made short delay, cells disappears often, and I don't want to leave big time reserve, because it looks like lags, so I want to solve this problem correctly. I tried to add [cell setNeedsDisplay] before returning cell from cellForRowAtIndexPath, but it doesn't work.

Any suggestion?

0

精彩评论

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