简体   繁体   English

阻止第二个模式视图出现?

[英]Prevent a second modal view from appearing?

I view controller that has different buttons a user can interact with. 我看到控制器具有用户可以与之交互的不同按钮。 Each one does something different, but they all present a new view controller modally. 每个人都做不同的事情,但是他们都以模态呈现了一个新的视图控制器。 The problem is that a user has time to tap another button before the first presentation has happened, which results in a crash. 问题是用户在第一个演示文稿发生之前有时间点击另一个按钮,这会导致崩溃。 Is there a way to prevent a user from tapping another button or detect if a modal presentation is already going to happen? 有没有一种方法可以防止用户点击另一个按钮或检测模态演示是否已经开始?

I just don't want to let users present more than 1 modal view controller at a time. 我只是不想让用户一次显示多个模式视图控制器。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

if ([[segue identifier] isEqualToString:@"whateverSegue"])
    {
    [button setEnabled:NO];
    }
}

This should do the trick if its just once - otherwise a helper method called disableButtons or something to call if its in a few places should do the trick! 如果只是一次,这应该可以解决问题-否则,一个名为disableButtons的帮助程序方法或一些地方可以调用的方法就可以解决问题!

Check whether following steps are helpful. 检查以下步骤是否有帮助。

Once you clicked button, you can disable the user interactions of the view. 单击按钮后,您可以禁用视图的用户交互。

-(IBAction)clickedButton:(id)sender {
   [self.view setUserInteractionEnabled:NO];

   // Do other things here
}

When model view controller appeared enable the user interactions of the view. 当模型视图控制器出现时,启用视图的用户交互。

[self presentViewController:aViewController animated:YES completion:^{
   [self.view setUserInteractionEnabled:NO];
}];

Alternatively you can try following methods to disable touches in your Application 另外,您可以尝试以下方法来禁用应用程序中的触摸

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

https://stackoverflow.com/a/16609327/1208276 https://stackoverflow.com/a/16609327/1208276

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM