Ios 无法关闭视图,按钮不可单击

Ios 无法关闭视图,按钮不可单击,ios,uialertview,dispatch-async,Ios,Uialertview,Dispatch Async,我有以下代码,其中显示了MBProgress视图,然后在单独的线程中运行代码。然后,我得到一个主线程的句柄,并关闭该微调器,然后显示一个UIAlertView。UIAlertView加载良好,但我无法单击任何按钮。如果警报视图在调度块之外,则可以正常工作。有什么想法吗 [MBProgressHUD showHUDAddedTo:self.view animated:YES]; dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRI

我有以下代码,其中显示了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];
        });
    }
});

在带块的线程外部声明警报视图:

__block UIAlertView *alert;

这可能是由于
MBProgressHUD
的动画与
UIAlertView
的动画之间的冲突导致的问题

我从未使用过
MBProgressHUD
,但看看GitHub上的代码,它们似乎已经解决了您的问题
MBProgressHUD
具有
completionBlock
属性

这样的代码应该可以工作:(警告:未测试)

MBProgressHUD
在视图完成其动画后触发其
completionBlock
,因此不再存在冲突

作为旁注,
MBProgressHUD
方法:

- (void)showAnimated:(BOOL)animated 
 whileExecutingBlock:(dispatch_block_t)block 
             onQueue:(dispatch_queue_t)queue
     completionBlock:(MBProgressHUDCompletionBlock)completion;

似乎它更适合您的代码。

如何在Swift中声明
- (void)showAnimated:(BOOL)animated 
 whileExecutingBlock:(dispatch_block_t)block 
             onQueue:(dispatch_queue_t)queue
     completionBlock:(MBProgressHUDCompletionBlock)completion;