我是做在单个线程一切才刚刚开始移动到异步调用,所以我有点糊涂了。
I was doing everything in a single thread and have just started moving to asynchronous calls so I'm a bit confused.
我想这样的观点来加载,无论是与一个空表或不带表都没有。该MBProgressHUD应该显示而异步调用获取数据。然后,当数据被发现HUD消失和表刷新。
What I would like is for the view to load, either with an empty table or with no table at all. The MBProgressHUD should show while the async call gets the data. Then when the data is found the HUD goes away and the table refreshes.
我现在拥有的是一切正常,除了HUD显示空桌子底下。这里是最相关的code。
What I have now is everything works except that the HUD is displayed underneath the empty table. Here is the most relevant code.
- (void)awakeFromNib { [super awakeFromNib]; [MBProgressHUD showHUDAddedTo:self.tableView animated:YES]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ self.dataController = [[StudyController alloc] initWithCredentials:email password:password]; dispatch_sync(dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUDForView:self.tableView animated:YES]; [self.tableView reloadData]; }); }); }基本上发生了什么,我想,是异步调用运行时调用毕竟我的code被渲染表正常运行一次,并显示在平视显示器顶部的空表,然后再次当我告诉它reloadData。我如何得到它不运行第一次?
Basically what is happening, I think, is all my code that was rendering the table correctly runs once while the async call is running, and shows an empty table on top of the HUD, and then again after the call when I tell it to reloadData. How do I get it to not run that first time?
感谢。
推荐答案这是很难没有看到你的表视图的委托/数据源的方法来衡量,但你的直觉是有道理的。在这种情况下,我可以看到两个选项:
It's hard to gauge without seeing your table view delegate/datasource methods, but your intuition makes sense. In this case, I can see two options:
我通常选择第二种方法,因为我preFER只专注于表视图我的数据源和委托方法。
I usually opt for the second method, because I prefer to focus my datasource and delegate methods on only the table view.
希望这有助于!
更多推荐
查看上显示加载图标上方,由于异步调用
发布评论