开发者

Initializing UITableView with remote data source

Edit: Originally this question contained a really stupid bug description I was experiencing but I've now figured out it was totally unrelated t开发者_运维问答o what I thought. So I'm just going to turn this into a UITableViews with remote data source best practices.

As a more general question: How does everyone like to handle UITableViews (or UIViews in general) with remote data sources (i.e. loaded via async NSURLConnections, sockets etc.)? What are some best practices for initializing the TableView data source before it has been loaded?

Does anyone want to provide examples or discussion regarding the use of asynchronous NSURLConnections or NSStreams with socket connections?


First you should check if the property of your datasource array really retains the object.

I've said "I've done the exact same thing" too often to believe it.


To the question of handling high latency data sources: the usual practice is to load the data in a background thread so that the UI remains responsive (NSoperation and NSOperationQueue are great for this, I use them frequently for this purpose), and to show a spinning activity indicator for any views whose contents are not ready yet but have been requested.

Only add the data to your model / user interface elements when it is finally available (using NSNotifications are a good way to signal that data is ready). The way to refresh your table view when more model / display data is available is to call [tableView reloadData].

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜