1

有没有办法让我在 5 秒后展示或关闭我的 ViewController?也许像......如果用户在 5 秒后按下按钮,则会出现新视图。

有什么解决方案或建议吗?抱歉,我没有在网上找到解决方案。

我的代码不起作用:

    -(IBAction)lol:(id)sender {

    [self performSelector:@selector(dissMissviewController) withObject:self afterDelay:3];
}

-(void)dissMissViewController{

    [self dismissModalViewControllerAnimated:YES];
}

谢谢。

4

2 回答 2

5

你可以用下面一个..

//for dismissing the ViewControler on clicking button just use below piece of code.

[self performSelector:@selector(dismissViewController) withObject:self afterDelay:5];

//dismissviewController is the method which has the code for dismissing the viewController.

//and can follow the same for showing the viewController.

 - (void)dismissViewController
 {
 //if you are pushing your viewControler, then use below single line code
 [self.navigationController popViewControllerAnimated:YES];
 //if you are presnting ViewController modally. then use below code
 [self dismissModalViewControllerAnimated:YES];
 }

我希望它可以清除给你......!

于 2012-11-13T18:02:36.393 回答
0

当您希望在按下按钮时延迟 5 秒后呈现或关闭新的 viewController,请尝试实现以下代码

       -(IBAction)btnpressed:(id)sender
       {
          [self performSelector:@selector(dismissVC) withObject:self afterDelay:5.0];

          //dismissVC is the method which has the code for dismissing the viewController. same is the case for presenting a ViewController by passing a selector which has the code for presenting the viewController

       }

希望这可以帮助。

于 2012-11-13T18:15:07.207 回答