我有以下代码,其中显示了MBProgress视图,然后在单独的线程中运行代码。然后,我得到了主线程的句柄,并关闭了工作的微调器,然后显示了UIAlertView。 UIAlertView加载正常,但是我无法单击任何按钮。如果警报视图在调度块之外,则可以正常工作。有任何想法吗?
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
// Do something...
GamePlayManager *gameManager = [GamePlayManager alloc];
Session *sess = [Session sharedInstance];
//Add the last actor to the end of the list
NSMutableDictionary *connections = sess.connections;
[connections setObject:sess.secondActor forKey:[NSString stringWithFormat:@"%d",kLastFieldtag]];
BOOL result = [gameManager areAnswersCorrect:sess.connections startingActor:sess.firstActor endingActor:sess.secondActor];
NSString *display = @"Sorry incorrect. Please recheck your answers.";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result"
message:display
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
if (result)
{
display = @"You are correct! You Won!";
if (sess.isMutiplayerGame)
{
[_gameCenterController endGame];
[self showGameOverScreen:YES isMultiplayer:YES];
}
else
{
[self showGameOverScreen:YES isMultiplayer:NO];
}
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
[alert show];
});
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
[alert show];
});
}
});
最佳答案
这可能是MBProgressHUD
的动画和UIAlertView
的动画之间发生冲突引起的问题。
我从未使用过MBProgressHUD
,但是在GitHub上查看代码似乎他们已经解决了您的问题。 MBProgressHUD
具有completionBlock
属性。
这样的代码应该可以正常工作:(警告:未经测试)
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD HUDForView:self.view].completionBlock = ^{
[alert show];
};
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
视图完成动画后,
MBProgressHUD
触发其completionBlock
,因此不再存在冲突。附带说明
MBProgressHUD
方法:- (void)showAnimated:(BOOL)animated
whileExecutingBlock:(dispatch_block_t)block
onQueue:(dispatch_queue_t)queue
completionBlock:(MBProgressHUDCompletionBlock)completion;
似乎更适合您的代码。
关于ios - 无法关闭UIAlertView,按钮不可单击,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13888805/