0
我的应用程序启动时加载了JSON。MBProgressHUD在重新加载数据时未显示
当数据加载时,MBProgressHUD正确显示微调器。
我也有一个触发重新加载JSON的刷新按钮 - 我希望它显示微调。虽然数据刷新,但微调不显示。
任何想法我做错了什么?
这里是我ViewController.m相关代码
- (void)viewDidLoad
{
[super viewDidLoad];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self fetchPosts];
}
- (IBAction)refresh:(id)sender {
[MBProgressHUD showHUDAddedTo:self.view animated:YES]; // NOT WORKING
[self refreshPosts];
}
- (void)fetchPosts
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString: @"http://mysite.com/app/"]];
NSError* error;
posts = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
});
});
}
- (void)refreshPosts
{
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString: @"http://mysite.com/app/"]];
NSError* error;
posts = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
});
}
您是否尝试在调度块中放置refreshPosts的整个代码(而不仅仅是调用reloadData)? – Ravi
@ravi这样做会产生一组单独的问题,其中刷新操作不响应点击刷新按钮 - 您认为您的建议是唯一的出路吗? – pepe
只是想知道,为什么不刷新行动回应?我肯定会尝试我的建议,看看它是否有效。我认为您的数据下载可能会导致界面冻结,从而可能会破坏HUD。 – Ravi