开发者

How to know when moving row is done

My app allows user to reorder rows in a table view, but I want to reloadData after moving is done to change something (add some text to the first row).

I tried to reloadData in moveRowAtIndexPath: method, but it makes the app hang because this method is called many tim开发者_开发技巧e (according number of rows need to be moved) and the table view is reload many time.

So, I just want to know when the moving behavior is done then I reloadData in just one time. Does anyone know about this? Please help me. Thanks you so much!


- (void)doReload
{
  [myTable reloadData];
}

You can do [self performSelector:selector(doReload) withObject:nil afterDelay:0.1] in the moveRowAtIndexPath method but you can't call [myTable reloadData] directly because as you found it causes a loop. Basically you need to allow the table manipulation to finish and the run loop to get around to calling your method which then causes a reload of your table. This is a bit of a hack but it works well. Ordinarily you don't need reloadData at this point but you may be trying to do something out of the ordinary.


-(int)table:(UITable*)table movedRow: (int)row toRow: (int)dest
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜