2

我有一个带有按钮的外部设备。当您按下此按钮时,它会切换视图控制器。当我慢慢按下按钮时,它们过渡得很好。但是,当我按下按钮太快时,应用程序会因错误而崩溃:

Terminating app due to uncaught exception NSInternalInconsistencyException, reason: Attempting to begin a modal transition from <SViewController: (numbers)> to <VViewController: (numbers)> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed

我不知道如何解决这个问题。这是我用来在视图控制器之间切换的代码。我把这个 if 语句放在每个视图控制器中(当然要切换视图控制器):

 if ([data isEqualToString: @"Switch1"]) {
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"VViewController"];
        vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentViewController:vc animated:YES completion:NULL];
    }

该错误表示检查viewDidLoad', but I have no idea what code to put inviewDidLoad` 以确定转换是否已完成,如果尚未完成,则阻止它再次尝试转换。

4

0 回答 0