zoukankan      html  css  js  c++  java
  • [NSUserDefaults]的使用:登陆后不再显示登录界面。

    简介:

    NSUserDefaults是IOS应用用来存储用户偏好和配置信息的途径,就像是一个数据库,但是它通过键值对(key-value)的方式存储。

    比如["Thematrix" forkey:"blogname"]

    使用方法:

    一共需要3个key,分别是"Didlogin" "username""userpassword"

    1.在AppDelegate的LaunchOption函数里:

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

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Override point for customization after application launch.
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"Didlogin"]){
    NSLog(@"未进行过登录,进行登录");
    LoginViewController *LoginViewController =[storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    self.window.rootViewController = LoginViewController;
    }
    else
    {
    NSLog(@"已经进行过登录,直接到首页");
    IndexViewController * IndexViewController = [storyboard instantiateViewControllerWithIdentifier:@"IndexViewController"];
    self.window.rootViewController = IndexViewController;
    }
    return YES;
    }
  • 相关阅读:
    Chrome浏览器与常用插件推荐
    时间戳 转换24小时制
    fis3 开启相对地址
    web手机端禁止滑动,web手机端禁止上下滑动。
    rem的用法
    手机端复制,pc端复制
    ruby 镜像安装
    使用Potree渲染大规模点云-踩坑记录
    移动端真机调试神器-spy-debugger
    手撕Promise.any
  • 原文地址:https://www.cnblogs.com/zhaoweizheng/p/4599852.html
Copyright © 2011-2022 走看看