更新数据异步后重绘UITableView [英] Redraw UITableView after updating data async

查看:101
本文介绍了更新数据异步后重绘UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableview,我加载了数据异步,所以tableview可能没有数据。

我已经厌倦了ReloadData方法但是tableview仍然是空的,直到我滚动tableview,突然出现了数据。

当我将tableview作为详细视图加载并在项目之间切换时,会发生同样的事情,首先出现previoud项目数据,当我在表格视图中滚动它显示正确的数据时。

我的猜测是ReloadData方法工作得很好,但我需要以某种方式重绘tableview,有关如何解决此问题的任何建议?

I have a UITableview that I load with data async so the tableview might appear without data.
I have tired the ReloadData method but the tableview remains empty until I scroll the tableview, suddenly the data appears.
The same thing happens when I load a tableview as a detailedview and switching between items, the previoud items data appears first and as soon as I scroll in the table view it shows the correct data.
My guess is that the ReloadData method works just fine, but I need to redraw the tableview somehow, any suggestions on how to solve this?

/ Jimmy

推荐答案

你说你是在异步填充内容但你是否在主线程的上下文中调用reloadData? (而不是通过填充内容的主题)

You said you're populating content asynchronously but did you invoke the reloadData in the context of the main thread ? (and not via the thread that populates the content)

Objective-C

[yourUITableView performSelectorOnMainThread:@selector(reloadData)
                                  withObject:nil 
                               waitUntilDone:NO];

Swift

dispatch_async(dispatch_get_main_queue(), { self.tableView.reloadData() })

Monotouch

InvokeOnMainThread(() => this.TableView.ReloadData());

这篇关于更新数据异步后重绘UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆