-1

I need to know how to move from first ui view controller to the second view controller after 5 seconds. How to define the time to move automatically, is it through the Navigation Controller and by which method?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2438318
  • 45
  • 1
  • 5
  • you should give [dispatch_after](https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html#//apple_ref/c/func/dispatch_after) a try and push the second viewcontroller on your navifationcontroller – CarlJ Oct 10 '13 at 12:46

3 Answers3

4

With performSelector:

- (void)viewDidLoad{

    [self performSelector:@selector(loadingNextView) 
               withObject:nil afterDelay:5.0f];
}

- (void)loadingNextView{

    myViewController = [[MyViewController alloc] init];
    [self.navigationController pushViewController:myViewController animated:YES];
}

Or with dispatch_after on main_queue:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5.0f * NSEC_PER_SEC),            
                dispatch_get_current_queue(), ^{

    [self loadingNextView];
});
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
3

You need to define a timer (or use GCD / performSelector:) to trigger a method call after your delay. Then in that method you can trigger the view controller change (how you do that depends on the relationship between the current and the next view controllers and is unaffected by the code to do the delay).

Wain
  • 118,658
  • 15
  • 128
  • 151
0

Use NSTimer or dispatch_after on main_queue.

Mercurial
  • 2,095
  • 4
  • 19
  • 33