管理登录/注销过渡的建议 [英] Suggestions to manage Login/Logout transitions
问题描述
我有一个仅在用户通过身份验证后才能使用的应用程序.特别是,我创建了两个不同的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 UIViewController
s.
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屋!