gpt4 book ai didi

ios - MBProgressHUD 方法返回值

转载 作者:行者123 更新时间:2023-11-29 01:51:00 25 4
gpt4 key购买 nike

所以我已经实现了 MBProgressHUD 但我想做的是用这行代码调用 MakePost 方法,它是 bool 值,如果正确发布的方法返回 YES 如果不是 NO

[HUD showWhileExecuting:@selector(MakePost:) onTarget:self withObject:@"1" animated:YES];

如果返回值是NO我想显示一个警告

UIAlertView* cError = [[UIAlertView alloc]initWithTitle:@"Error try later!" message:@"Post Error" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[cError show];

最佳答案

可以使用方法:

/**
* 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];
}
}];

}

关于ios - MBProgressHUD 方法返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31418077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com