可以使用故事板登录屏幕吗? [英] Login Screen with Storyboarding possible?
问题描述
我正在使用新的iOS 5功能并尝试使用新的故事板功能将我的应用程序重写为纯iOS 5应用程序。
I am playing around with the new iOS 5 features and trying to rewriting one of my apps as pure iOS 5 app using the new storyboarding feature.
要剪切一个长话短说,我有一个开始屏幕,如果用户保存了一些登录数据,应用程序尝试连接到服务器,如果没有,它应该要求它们。
To cut a long story short, I have a start screen where the app tries to connect to a server if the user saved some login data, if not, it should ask for them.
我就是这样做的。我创建了一个Viewcontroller,它在viewDidLoad方法中执行连接。如果没有登录数据或登录不成功,我需要在登录屏幕上进行手动操作。
Here is how I would do it. I create a Viewcontroller which is doing the connection thing in the viewDidLoad method. If there is no login data or the login is not successful, I need a to do a manual segue to the login screen.
现在这是可能的,或者我是需要2个故事板吗?
Now is this even possible, or do I need 2 story boards for that ?
推荐答案
我已经通过放置一个没有任何segues的登录视图(来自或来自它)解决了它如下面的屏幕截图所示:
I have solved it by putting a login view without any segues (to or from it) like in the screenshot below:
然后,我在标签栏控制器中使用了一个自定义类,以便在需要时显示它。
Then, I used a custom class in the tab bar controller to show it whenever I need it.
在标签栏控制器类中,我使用'viewDidLoad'来启动登录视图。为了显示模态视图,我确实有一个单独的东西存储一些状态,比如BOOL isAuthenticated,我做魔术:
In the tab bar controller class, I use 'viewDidLoad' to fire up the login view. To show the modal view, I do have a singleton thingy that stores some state, say BOOL isAuthenticated, where I do the magic:
- (void) performLoginIfRequired: (UIViewController *) source {
if (!self.isAuthenticated) {
NSLog(@"Is not authed");
UIStoryboard *storyboard = [UIApplication sharedApplication].delegate.window.rootViewController.storyboard;
UIViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"loginScreen"];
[source presentModalViewController:loginController animated:YES];
} else {
NSLog(@"Is authe");
}
}
而且,就我而言,我希望它在应用程序首次启动时显示,但也在它再次进入前景时显示。所以,我在通知中心注册了我的标签栏控制器,因此我会在应用程序回来时收到通知:
And, in my case, I wanted it to be shown when the app first starts, but also when it enters foreground again. So, I registered my tab bar controller with the notification center, so I get notified if the app is coming back:
-(void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
在willEnterForeground方法中,我这样做:
In the willEnterForeground method, I do:
-(void) willEnterForeground: (NSNotification *)notification {
[[myStateThingy defaultState] performLoginIfRequired:self];
}
这篇关于可以使用故事板登录屏幕吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!