管理登录/注销过渡的建议 [英] Suggestions to manage Login/Logout transitions

查看:76
本文介绍了管理登录/注销过渡的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个仅在用户通过身份验证后才能使用的应用程序.特别是,我创建了两个不同的UIViewController.第一个称为LoginViewController,第二个称为HomeViewController.在applicationDidFinishLaunching:方法中,将创建LoginViewController,然后将其添加到rootViewController属性中,如下所示:

LoginViewController* loginCtr = ... // alloc and initiWithNibName... 
self.window.rootViewController = loginCTr;
[loginCtr release];

Whitin LoginViewController我创建了一个执行登录的方法.对用户进行身份验证后,我将执行一种称为performLogin的方法.

- (void)performLogin
{
  MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
  [appDelegate switchView];    
}

其中swicthView方法已在Application委托类中实现.

- (void)switchView
{
   if(VIEW_TYPE == kLogin) // Display Login
   {
     // create a new LoginViewController and assign it to rootViewController
   }

   else // Display Home
   {
     // create a new HomeViewController and assign it to rootViewController
   }
}

考虑到先前的代码,是否有可能实现一种更优雅的机制来管理登录/注销转换,或者这种实现方式可以被视为有价值的解决方案?

谢谢.

解决方案

从iOS 5开始,我开始使用针对UIViewController的新包含API来管理登录/注销转换.

编写高质量视图控制器.

希望有帮助.

I have an application that can be used only if the user is authenticated. In particular, I created two different UIViewController. The first is called LoginViewController while the second is called HomeViewController. In applicationDidFinishLaunching: method, LoginViewController is created and then added to rootViewController property like this:

LoginViewController* loginCtr = ... // alloc and initiWithNibName... 
self.window.rootViewController = loginCTr;
[loginCtr release];

Whitin LoginViewController I created a method that performs the login. When the user has been authenticated, I perform a method, called performLogin.

- (void)performLogin
{
  MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
  [appDelegate switchView];    
}

where swicthView method has been implemented inside the Application delegate class.

- (void)switchView
{
   if(VIEW_TYPE == kLogin) // Display Login
   {
     // create a new LoginViewController and assign it to rootViewController
   }

   else // Display Home
   {
     // create a new HomeViewController and assign it to rootViewController
   }
}

Given the previous code, is it possible to implement a more elegant mechanism to manage login / logout transition or does this type of implementation could be considered a valuable solution?

Thank you in advance.

解决方案

Starting from iOS 5 I started to manage login/logout transitions using the new containment API for UIViewControllers.

Implementing a Container View Controller

If iOS 5 is not available I would see a similar approach writing-high-quality-view-controller.

Hope that helps.

这篇关于管理登录/注销过渡的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆