首页 > 编程语言 > 详细

如何让UITableView加载完成后更新UI回到主线程

时间:2016-06-13 15:17:10      阅读:220      评论:0      收藏:0      [点我收藏+]
tableView加载完毕后回调的delegate方法: -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){ //end of loading //for example [activityIndicator stopAnimating]; } } ++++++++++++++++++++++++++++++++++++++ 由于willDisplayCell是异步调用的,所以在上面的block里面不能即时更新UI,最好使用GCD通过主线程加上你的代码: -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){ //end of loading dispatch_async(dispatch_get_main_queue,^{ //for example [activityIndicator stopAnimating]; }); } }

如何让UITableView加载完成后更新UI回到主线程

原文:http://www.cnblogs.com/duyuiOS/p/5580545.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!