I am trying to build a splash screen so I want the 1st View Controller to move to 2nd ViwController automatically after 3.0 sec I have tried the below method but an infinite loop has started what should i do ,how should I stop on second view controller.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"%p", self);
NSLog(@"1st Controller");
[self.navigationController setNavigationBarHidden:YES animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self loadingNextView];
});
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)loadingNextView{
LoginViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController pushViewController:viewController animated:true];
}
//LoginViewController.h
@interface LoginViewController : ViewController
@end
//LoginViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"2nd View Controller");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
You can achieve you goal by using this.
Why don't you use
NSTimer
class. Simply create a timer for 10 seconds when 10 seconds passed timer will trigger the event and in that event you can move to anothercontroller
. Create a timer like thisFinally got the answer.
It is easy to do, you can add a property to judge if is first come in the vc1:
The result:
In fitst VC:
Try this
So a little advise, you should think about presenting a loginViewController instead pushing it to the NavigationController stack. If you push it, you have to remove the back buttons if you don't want the user to come back to the other ViewController. If you present it you can be sure that the user can't go back to the firstVc without entering his login data.
In the second Vc you then can dismiss the Vc or you can present a new ViewController.