2016-11-04 7 views
0

私はiPhoneアプリケーションを構築しています、私AppDelegateで、私は(ユーザーがログインしている場合は)私のHomeViewをロードするために、このコードを使用します。HomeViewControllerでIOSログインサインアップ家のためのベストプラクティス

if(isLoggedIn==YES) 
{ 
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 

    [self.window setRootViewController:(HomeViewController *)[sb instantiateViewControllerWithIdentifier:@"homeScreen"]]; 

} 

私のユーザーのログアウト私はこのコードを使用してLoginViewControllerに切り替えます:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
self.view.window.rootViewController = (LoginViewController *)[sb instantiateViewControllerWithIdentifier:@"loginScreen"]; 

私はベストプラクティスを教えてください。 RootViewと現在のログイン画面など

おかげ

+0

セットhomeviewコントローラユーザーがログインしていない場合は、ログアウトボタンをクリックし、もう一度モーダルビューとして – Vinodh

+0

をLoginViewを提示した後、あなたは、このためのNSUserDefaultsがすべき –

答えて

2
///Appdelegate.h 

@property (strong, nonatomic) UINavigationController *navigationController; 

/////Appdelegate.m 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; 

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
if(!isLoggedIn) 
{ 
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"loginScreen"]; 
     _navigationController=[[UINavigationController alloc]initWithRootViewController:viewController]; 

    } 

else 
{ 
    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"homeScreen"]; 
     _navigationController=[[UINavigationController alloc]initWithRootViewController:viewController]; 

} 
self.window.rootViewController = self.navigationController; 
     [self.window makeKeyAndVisible];  
} 
////logout_action 

-(IBAction)myprofile:(id)sender 
{ 
islogged=NO; 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    MyprofileViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"loginScreen"]; 
    [self.navigationController pushViewController:viewController animated:YES]; 
} 
関連する問題