2016-11-04 2 views
0

Ich bin eine iPhone-Anwendung erstellen, in meinem AppDelegate ich diesen Code verwenden, um meine Homeview laden (wenn Benutzer angemeldet ist):IOS Best Practices für die Anmeldung Anmeldungen zu Hause

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

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

} 

In HomeViewController wenn mein Benutzer abmelden Ich verwende diesen Code, um zu LoginViewController zu wechseln:

Könnten Sie bitte beraten Sie mir die Best Practices?

Dank

+0

Set Homeview Controller als RootView und Gegenwart Anmeldebildschirm, wenn der Benutzer nicht angemeldet, nach Klick Logout-Button erneut die Loginview als modale Ansicht – Vinodh

+0

Sie präsentieren sollte für diese NSUserDefaults –

Antwort

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]; 
}