I want to set up an authentication process whereby users will first be directed to a login screen where they can input their credentials and would only be directed to the home page if authenticated successfully.
Based on a tutorial found online ( http://sapandiwakar.in/programatically-set-the-initial-view-controller-using-storyboards/ ) I understand that I can use delegates to do so. However I do not know
application:didFinishLaunchingWithOptions:
method viewcontroller
navigationcontroller
How can l know how to do so?
If I understood your question correctly. You want to direct your user to a login view if he/she is not logged in. Otherwise you will direct him/her to the main view.
You can try this way:
Here's a sample:
In your ContainerViewController.m :
- (void)viewDidLoad
{
if(isUserLoggedIn)
{
[self loadMainView];
}
else
{
[self loadLoginView];
}
}
- (void)loadMainView
{
UIViewController mainViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainView"];
[self addChildViewController:mainViewController];
[self.view addSubview:mainViewController.view];
[mainViewController didMoveToParentViewController:self];
[mainViewController.view setFrame:self.view.bounds];
}
- (void)loadLoginView
{
UIViewController loginViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
[self addChildViewController:loginViewController];
[self.view addSubview:loginViewController.view];
[loginViewController didMoveToParentViewController:self];
[loginViewController.view setFrame:self.view.bounds];
}
Take note: You don't need to set segue between the container and the other two view controllers.
Hope this helps. :)
set your login screen as a initial view controller then do your signin process if successful navigate app to home screen using below code else leave appropriate message..
// you need to create UIStoryboard object by giving name of your storyboard
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// here you need to create storyboard ID of perticular view where you need to navigate your app
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewContIdentifire"];
// if use presentViewController this will not enables you to go back to previous view
[self presentViewController:vc animated:NO completion:nil];
**// OR**
// using pushViewController lets you to go back to the previous view
[self.navigationController pushViewController:vc animated:YES];
Hope this helps ..
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.