2012-11-13 41 views
0

有没有办法,我可以在5秒钟后呈现或解散我的ViewController?也许就像...如果用户在5秒钟后按下按钮,则会出现新视图。在一段时间间隔后关闭ViewController?

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

我的代码不工作:

-(IBAction)lol:(id)sender { 

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

-(void)dissMissViewController{ 

    [self dismissModalViewControllerAnimated:YES]; 
} 

感谢。

回答

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]; 
} 

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

+0

我得到这个错误:终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因是:“ - [视图控制器dissMissviewController]:无法识别的选择发送到实例0x2083d170” – MasterRazer

+0

@NoahRaissi它MEA你应该定义使用该方法,正如我所说的你已经定义了使用它的方法...... !!!是那么清楚,所以请在你同一班的某个地方宣布它 – Kamarshad

+0

对不起,我是一个新手感冒,你给我做一个例子吗? – MasterRazer

0

正如你想,当按下按钮一个新的viewController提出或5秒的延迟之后被解雇,尝试实现下面的代码

 -(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 

     } 

希望这有助于。

+1

anwser已经发布,但感谢 – MasterRazer

+0

它没关系,好​​你是通过它。 –

+0

:D你看到:D! – MasterRazer

相关问题