我正在制作一款应用。首先用户必须登录,然后他才允许使用该应用程序。
成功登录后,我希望用户直接切换到我的HomeViewController。
这是我的代码更改导航根视图但它无法正常工作
TermsConditionsController *firstViewController = [[TermsConditionsController alloc]init];
FirstPage *secondViewController = [[FirstPage alloc]init];
firstViewController.navigationController.viewControllers = [NSArray arrayWithObject: secondViewController];
FirstPage *nextScr = (FirstPage *) [self.storyboard instantiateViewControllerWithIdentifier:@"FirstPage"];
[self.navigationController pushViewController:nextScr animated:YES];
答案 0 :(得分:0)
试试此代码
注意:根据您的控制器更改控制器名称
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navController;
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"loginUserDetails"]) {
// Already logged in
ProfileViewController *profileVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ProfileVC"];
navController = [[UINavigationController alloc]initWithRootViewController:profileVC];
}else{
// Not Login Yet
LoginViewController *loginVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginVC"];
navController = [[UINavigationController alloc]initWithRootViewController:loginVC];
}
self.window.rootViewController = navController;
}
// Write this code when user login successfully
if (/*Login Successfully*/) {
// Then add loginUserDetails in userdefaults.
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"loginUserDetails"];// Instead of nil pass here your object
[[NSUserDefaults standardUserDefaults] synchronize];
}