美文网首页Xib的使用
Storyboard 登录屏以及注销时处理数据清除的最佳实践

Storyboard 登录屏以及注销时处理数据清除的最佳实践

作者: 张嘉夫 | 来源:发表于2016-08-24 00:24 被阅读71次

    在 appDelegate.m 里的 didFinishLaunchingWithOptions

    //authenticatedUser: 检查 NSUserDefaults 里的用户证书,如果存在就根据它设置导航流程
    
    if (authenticatedUser) 
    {
        self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];        
    }
    else
    {
        UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];
        UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
    
        self.window.rootViewController = navigation;
    }
    

    在 SignUpViewController.m 文件

    - (IBAction)actionSignup:(id)sender
    {
        AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
    
        appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
    }
    

    在 MyTabThreeViewController.m 文件

    - (IBAction)actionLogout:(id)sender {
    
        // 从 NSUserDefaults 中删除用户证书,以及其他用户相关数据
    
        AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
    
        UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];
    
        UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
        appDelegateTemp.window.rootViewController = navigation;
    
    }

    相关文章

      网友评论

        本文标题:Storyboard 登录屏以及注销时处理数据清除的最佳实践

        本文链接:https://www.haomeiwen.com/subject/ucbnsttx.html