怎么设计IOS登录页面的跳转关系

各种介绍简单的API调用的书很多,但是对于日常开发经常碰到的问题很少有介绍。我这里摘录翻译了一些大家推荐的模式,比如常见的登录窗口需求如下:
-第一次启动应用程序时显示登录屏幕。登录后,转到标签栏控制器的第一个选项卡。
-任何时候他们启动应用程序,检查他们是否登录,并直接跳到根Tab键控制器的第一个选项卡。
-当他们手动点击注销按钮时,显示登录屏幕,并从视图控制器中清除所有数据。
在实现细节上:
-在需要的地方检察登录状态,按需执行注销操作的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutAccount) name:@"logoutAccount" object:nil];
-在注销时,清除钥匙串中的凭据,然后执行segue再次显示登录视图控制器。
那么通用的流程是:

img_e464cc79221501554f8370284f6a6646.jpe
qpwis.jpg

在appDelegate.m里面的didFinishLaunchingWithOptions

//用户认证: 检查 NSUserDefaults User credential 是否存在,引导页面跳转

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;

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值