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?
Asked
Active
Viewed 5,446 times
-1
-
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 Answers
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
-
-
-
just see all the other answered questions at stackoverflow like [HERE](http://stackoverflow.com/questions/920675/how-can-i-delay-a-method-call-for-1-second). – JFS Oct 10 '13 at 13:17