Revert to previous controller after xx amount of s

2020-05-04 07:19发布

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?

1条回答
SAY GOODBYE
2楼-- · 2020-05-04 07:58

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];
 }
查看更多
登录 后发表回答