所以我已经实现了MBProgressHUD但我试图做的是用这行代码调用布尔的MakePost
方法,如果正确发布的方法返回YES
,如果不是{ {1}}
NO
如果返回值为[HUD showWhileExecuting:@selector(MakePost:) onTarget:self withObject:@"1" animated:YES];
,我想显示提醒
NO
答案 0 :(得分:1)
您可以使用以下方法:
/**
* Shows the HUD while a block is executing on a background queue, then hides the HUD.
*/
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion;
按照代码中的评论:
- (IBAction)buttonClicked:(id)sender
{
// setup our alert we use UIAlertController instead of deprecated UIAlertView
self.alertController = [UIAlertController alertControllerWithTitle: @"Alert"
message: @"Hey are you ok ?"
preferredStyle: UIAlertControllerStyleAlert];
// we will store the result of the method "makePost" lowercase ;)
__block BOOL result;
// setup the HUD
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"Loading";
[hud showAnimated:YES whileExecutingBlock:^{
result = [self MakePost];
} completionBlock:^{
if (result)
{
NSLog(@"OK");
}
else
{
[self presentViewController: self.alertController animated: true completion: nil];
}
}];
}