简体   繁体   English

在ObjectiveC中使用标签栏和导航栏显示UIView

[英]Displaying UIView with Tab Bar and Navigation Bar in ObjectiveC

I'm developing an app that requires the user to login for full functionality, but will allow the user to skip logging in to browse around. 我正在开发一个要求用户登录才能使用全部功能的应用程序,但允许用户跳过登录后浏览。

In my storyboard, I have a UIViewController that acts as the Login screen. 在我的情节提要中,我有一个UIViewController充当“登录”屏幕。 When I click the Skip button, it goes onto the next screen. 当我单击“跳过”按钮时,它将进入下一个屏幕。

Here is when I run into problems... I want the screen that pops up when the user presses skip to have a Navigation bar and a Tab Bar. 这是当我遇到问题时...我希望当用户按下“跳过”以显示一个导航栏和一个标签栏时弹出的屏幕。 I add those two things in and it works. 我在其中添加了两件事,并且可以正常工作。

In my app delegate file I check to see if the user has skipped the app to go straight into the Menu Screen. 在我的应用程序委托文件中,我检查用户是否已跳过应用程序而直接进入菜单屏幕。 The problem is, it just goes to a blank white screen without the navigation bar and the tab bar. 问题是,它只是进入了空白的空白屏幕,而没有导航栏和标签栏。 It works fine when I press skip, but not when I relaunch the app after closing it. 当我按“跳过”时,它工作正常,但在关闭应用程序后重新启动该应用程序时,效果不佳。

Here is the code that checks if the user has skipped the login: 以下是检查用户是否跳过登录的代码:

//Check NSUserDefaults to get the value for skipLogin
     BOOL skipLogin = [[NSUserDefaults standardUserDefaults] objectForKey:kACUserDefaultsSkippedLoginKey];

//Check to see if the user has logged in or has already pressed the skip button.
//If not, show the LoginViewController
     if(skipLogin || [PFUser currentUser]) {
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
     MenuViewController *menuView = [storyboard instantiateViewControllerWithIdentifier:@"MenuView"];
     self.window.rootViewController = menuView;
     }else{
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
     LoginViewController *loginView = [storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
     self.window.rootViewController = loginView;
     }

What am I doing wrong? 我究竟做错了什么?

Why don't you use performSegueWithIdentifier to push the new view controller? 为什么不使用performSegueWithIdentifier来推送新的视图控制器? Maybe the problem is that you are loading the storyboard and you are setting also the rootViewController of the window. 也许问题是您正在加载情节提要,并且还设置了窗口的rootViewController。

I went ahead and switched the Initial View Controller to be set to the Menu View and if the user hasn't logged in or skipped login, I just pop up the Login View. 我继续将“初始视图控制器”设置为“菜单视图”,如果用户尚未登录或跳过登录,则仅弹出“登录视图”。 It works much better that way. 这样效果更好。

Thank you guys for your help! 谢谢你们的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM