реализовать метод didFinishLaunching таким образом:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
BOOL isLogin = [[NSUserDefaults standardUserDefaults] boolForKey:@"IS_LOGIN"];
if (isLogin == YES)
{
rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"MainHomeView"];
}
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
И истинна при нажатии кнопки входа
- (IBAction)login:(id)sender
{
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"IS_LOGIN"];
[[NSUserDefaults standardUserDefaults] synchronize];
HomeViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainHomeView"];
AppDelegate *appDelagate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelagate.window.rootViewController = vc;
}
Небольшое улучшение: сохраните память загрузки контроллеров двойного представления, сначала определив «IS_LOGIN», затем загрузите 'rootViewController'. В вашем коде, если 'isLogin'' YES', 'storyboard instantiateViewControllerWithIdentifier:' вызывается дважды. – Raptor
Спасибо ... @Raptor – VRAwesome
Или вы можете положить его в другом случае. – VRAwesome