我正在使用MBProgressHUD
自定義控件顯示從Web加載JSON數據時的情況。MBProgressHUD未在iOS中顯示
我已經在他們的視圖中找到很多不能正確顯示HUD控制的答案。
這是我的代碼在我的視圖中顯示HUD
。
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
以下是我如何隱藏我的HUD
視圖。
[MBProgressHUD hideHUDForView:self.view animated:YES];
在ViewDidLoad中,該控件工作正常。
但是,當我點擊刷新按鈕,並希望顯示HUD控制時,它不顯示HUD控制。
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_queue_t myqueue = dispatch_queue_create("queue", NULL);
dispatch_async(myqueue, ^{
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:nil waitUntilDone:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tbl reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});
我不知道我做錯了什麼?請幫幫我。
即使你做了一堆調度,你所有的工作都在主隊列上結束!這將阻止用戶界面,HUD不會顯示。 – Jack
那麼,如何編輯我的代碼? –
嘗試調用fetchedData:直接而不是在主線程上執行,看看是否一切仍然有效 – Jack