【发布时间】:2015-01-06 11:42:03
【问题描述】:
我的应用程序从网络下载 json,用图钉绘制地图并在表格视图中显示数据。
地图不是问题,因为我编写了我的自定义函数来绘制地图并在 dispatch_async(dispatch_get_main_queue() 行之后立即调用它,这很好 - 地图正在等待下载数据。但是,问题来了我想对表格视图做同样的事情。
我的代码很长,所以我将只显示简短的 sn-ps 以了解问题所在。
我尝试了以下修改:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
// Do any additional setup after loading the view, typically from a nib.
self.tableView.backgroundColor = UIColor.clearColor();
self.tableView.delegate = self;
self.tableView.dataSource = self;
但不幸的是,它没有任何帮助 - 在下载数据之前再次加载表格视图,这会导致一个空表格。
表格视图使用自己的预定义功能,例如:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
并且将它们放入异步任务中是不可能没有错误的
我的问题是:如何处理那种东西(我的意思是当你想要一个元素比如表格视图“等待”数据首先被下载并且你不能把它放在下载任务中)?
希望我能比较清楚地提出问题,提前谢谢
【问题讨论】:
标签: ios cocoa-touch swift