简体   繁体   中英

Revert to previous controller after xx amount of seconds

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?

try this code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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