在Tab Bar控制器之前显示登录屏幕 [英] Show a login screen before a Tab Bar Controller

查看:124
本文介绍了在Tab Bar控制器之前显示登录屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个Twitter应用程序,并在AppDelegate -didFinishLaunchingWithOptions 我使用下一个代码来加载登录视图,如果该对象的NSUserDefaults是空的: / p>

NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];

  NSString * test = [prefs objectForKey:@username]; 
if(test == @(null)|| test == nil){
LoginScreenViewController * login = [[LoginScreenViewController alloc] initWithNibName:@LoginScreenViewControllerbundle:nil];
[self.window addSubview:login.view];
[self.window makeKeyAndVisible];

} else {
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
}

我可以加载登录视图,解散?登录屏幕必须在加载tabBarController之前显示,因此当Login控制器完成后,选项卡栏控制器将启动,就像之前没有任何其他视图一样。提前感谢!

解决方案

我不知道这是否会解决你的问题,但不要使用== for string比较。使用 NSString 类的 compare:方法。

  if([myNSStringObject compare:anotherNSStringObject] == NSOrderedSame){
//继续根据结果匹配的字符串进行处理
}
else {
//继续根据结果不匹配的字符串进行处理
}

不确定如果这将产生影响,但是当你的程序变得更复杂,你可能会遇到麻烦,不这样做。


I'm doing an Twitter app, and on the AppDelegate -didFinishLaunchingWithOptions I'm using next code for loading the login view if NSUserDefaults on that object are empty:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

NSString *test = [prefs objectForKey:@"username"];
if (test == @"(null)" || test == nil) {
    LoginScreenViewController *login = [[LoginScreenViewController alloc] initWithNibName:@"LoginScreenViewController" bundle:nil];
    [self.window addSubview:login.view];
    [self.window makeKeyAndVisible];

} else {
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];
}

And I'm able to load the login view, but then how would I dismiss it? The login screen has to show up before the tabBarController is loaded, so when the Login controller is done, the tab bar controller gets started as if it wouldn't have any other view before. Thanks in advance!

解决方案

I'm not sure if this will solve your problem, but don't use == for string comparisons. Use the compare: method of the NSString class.

if ([myNSStringObject compare:anotherNSStringObject] == NSOrderedSame) {
   //proceed with processing based on resultant matched strings
}
else {
   //proceed with processing based on resultant non-matched strings
}

Not sure if this will make a difference, but as your program becomes more complex, you might run into trouble not doing it this way.

这篇关于在Tab Bar控制器之前显示登录屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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