xx秒后恢复到之前的控制器 [英] Revert to previous controller after xx amount of seconds
问题描述
我有一个非常简单的应用程序,代码很少。在我的ViewController中,我没有完成任何代码,我只添加了一个导航栏,其中包含一个带有VideoController模态的下一个按钮。我想要实现的是在ViewController中按下下一个按钮后,允许用户查看VideoController 5秒钟,然后自动返回到上一个ViewController。这是我在VideoController.m中添加的代码
I have a very simple app with very little code. In my ViewController I have done no code, I have only added a navigation bar which contains a next button with a modal to the VideoController. What I would like to achieve is after the next button is pushed in ViewController, allow the user to view VideoController for 5 seconds and then automatically return to the previous ViewController. Here is the code I have added in my VideoController.m
#import "VideoController.h"
@interface VideoController ()
@end
@implementation VideoController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//code added
[self performSelector:@selector(goBack) withObject:nil afterDelay:5.0];
}
//code added
-(void)goBack{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
\
@end
我没有收到任何错误,但这并没有按照需要将我恢复到上一页。我错过了什么?
I am not receiving any errors however this is not reverting me back to the previous page as desired. What am I missing?
推荐答案
试试这段代码
- (void)viewDidLoad
{
[super viewDidLoad];
//code added
//[self performSelector:@selector(goBack) withObject:nil afterDelay:5.0];
[NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(goBack)
userInfo:nil repeats:NO];
}
//code added
-(void)goBack{
[self.navigationController popViewControllerAnimated:YES];
}
这篇关于xx秒后恢复到之前的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!