一段时间后解除ViewController?

时间:2012-11-13 17:58:53

标签: iphone objective-c ios uiviewcontroller

有没有办法,我可以在5秒后呈现或解散我的ViewController?也许是......如果用户在5秒后按下按钮,则会出现新视图。

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

我的代码不起作用:

    -(IBAction)lol:(id)sender {

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

-(void)dissMissViewController{

    [self dismissModalViewControllerAnimated:YES];
}

感谢。

2 个答案:

答案 0 :(得分: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];
 }

我希望它可以让你清楚...... !!!

答案 1 :(得分: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

       }

希望这有帮助。

相关问题