2017-01-29 143 views
0

我正在嘗試從不顯示用戶登錄看法,如果他在 登錄我在viewWillAppear中隱藏登錄查看,如果用戶登錄

-(void)viewWillAppear:(BOOL)animated 
{ 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 

    if ([defaults objectForKey:@"userName"]) { 

     NSDictionary *d = [defaults objectForKey:@"currentUser"]; 
     UserProfile *userData = [[UserProfile alloc]initWithDictionary:d]; 
     [[NetworkModel sharedManager] setCurrentUser:hh]; 
     [self loginResults]; 
    } 

    self.navigationController.navigationBarHidden = YES; 

} 

做到這一點,loginResults功能

-(void)childrenReceived:(NSNotification *) notification 
    { 
     [SVProgressHUD dismiss]; 
     NSDictionary *userInfo = notification.userInfo; 
     NSArray *allKids = [userInfo objectForKey:@"children"]; 
     RootViewController *sideBarRoot= [self.storyboard instantiateViewControllerWithIdentifier:@"root"]; 
     sideBarRoot.children = allKids; 
     [self dismissViewControllerAnimated:YES completion:nil]; 
     [self presentViewController:sideBarRoot animated:YES completion:nil]; 
} 
+0

什麼是問題? – jesse

+0

你想做什麼?請編輯您的問題以提供更多信息並閱讀[如何提問](http://stackoverflow.com/help/how-to-ask)。 –

+0

檢查此:http://stackoverflow.com/questions/41864151/how-to-present-login-screen-only-when-a-userdefaults-key-doesnt-exist/41864888#41864888 – aircraft

回答

1

檢查以下編碼

@interface AppDelegate : UIResponder <UIApplicationDelegate> 
-(void) didFinishLogin 
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
    CCKFNavDrawer*homeNavController = (CCKFNavDrawer*)[mainStoryboard instantiateViewControllerWithIdentifier:@"NavigationLoginID"]; 
    [self.window makeKeyAndVisible]; 
    self.window.rootViewController = homeNavController; 

-(void)didFinishLogout 

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
    UINavigationController *homeNavController = (UINavigationController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"LoginNavigationID"]; 
    LoginVC *objloginVC = (LoginVC*)[homeNavController topViewController]; 
    objloginVC.delegate=self; 
    [self.window makeKeyAndVisible]; 
    self.window.rootViewController = homeNavController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
     if([[[NSUserDefaults standardUserDefaults]objectforkey:@"loginKey"]isequaltostring:@""]) 
     [self didFinishLogout]; 

     else 
     [self didFinishLogin];