我正在使用MBProgressHUD和STTwitter ......我调用MBProgressHUD,然后从主线程加载twitter feed并隐藏HUD。不幸的是,HUD一收到响应就会隐藏,而不一定在数据完全下载后隐藏。这个问题有方法解决吗?这也适用于应用程序中其他位置的Web视图。谢谢!
[[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
//Sets the auth key (user or app) for the RMACC Twitter Feed
STTwitterAPI *twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[twitter getUserTimelineWithScreenName:@"RMACCNewsNotes" count: 10 successBlock:^(NSArray *statuses) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
self.twitterFeed =[NSMutableArray arrayWithArray:statuses];
[self.tableView reloadData];
}
errorBlock:^(NSError *error){
}];
} errorBlock:^(NSError *error) {
[self twitterselfauthrequest];
}];
});
}
答案 0 :(得分:1)
我建议使用易于使用的SVProgressHUD,实现Singleton,以及更多功能和控制
答案 1 :(得分:0)
将HUD
隐藏代码移至successBlock
内,如下所示
successBlock: ^(NSArray *statuses) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
self.twitterFeed =[NSMutableArray arrayWithArray:statuses];
[self.tableView reloadData];
}
答案 2 :(得分:0)
尝试将dispatch_async
更改为dispatch_sync
。
我认为这可能会发生,因为dispatch_async在主线程上有一些问题。