在显示标签栏控制器之前启动登录视图 [英] Launching a login view before the tab bar controller is displayed

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

问题描述

我有一个使用故事板开发的 ios5 应用程序,当前在初始启动时显示标签栏控制器视图.我想在显示标签栏控制器之前显示登录屏幕.用户将输入他的用户名 &密码,系统将验证用户,如果成功,则显示标签栏控制器.

I have an ios5 app developed using storyboards that currently displays a tab bar controller view on initial launch. I would like to display a login screen before the tab bar controller is displayed. The user would enter his username & password, the system would then authenticate the user and then if successful, display the tab bar controller.

我尝试了以下 3 个选项,但都没有成功......有什么想法吗?

I have tried the following 3 options with no luck.. any ideas ?

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // Option 1
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    PointsViewController *firstVC = [[tabBarController viewControllers] objectAtIndex:0];
    UIViewController *loginViewController = [[LoginViewController alloc] init];
    [firstVC.navigationController pushViewController:loginViewController animated:YES];

    // Option 2
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UIViewController *loginViewController = [[LoginViewController alloc] init];
    [tabBarController presentViewController:loginViewController animated:NO completion:nil];  

    // Option 3
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UIViewController *loginViewController = [[LoginViewController alloc] init];
    [tabBarController presentModalViewController:loginViewController animated:NO];

    return YES;
}

推荐答案

终于想通了.. 这是你需要做的:

Finally figured this one out.. here is what you need to do:

  1. 向情节提要添加一个独立的登录视图.

  1. Add a standalone login view to the storyboard.

选择登录视图并在属性检查器中,选中是初始视图控制器".这会将启动的初始视图从选项卡控制器切换到登录视图,从而解决首先显示登录屏幕的整个问题.

Select the login view and in the attributes inspector, check the 'Is Initial View Controller'. This will switch the initial view being launched from the tab controller to the login view, thereby solving the whole issue of displaying the login screen first.

向登录视图添加一个按钮,并创建一个 segue 以在按下按钮时加载选项卡控制器.(或者,您可以创建从登录视图到选项卡控制器视图的 segue,并根据需要以编程方式调用 segue).

Add a button to the login view and create a segue to load the tab controller on push of the button. (Or you can create a segue from the login view to the tab controller view and programmatically invoke the segue as necessary).

选择登录视图并选择选项 Editor > Embed In > Navigation Controller

Select the login view and choose option Editor > Embed In > Navigation Controller

在导航控制器的属性检查器中,取消选中显示导航栏"选项(这是一个装饰性更改;我假设您不需要在登录屏幕上显示导航栏!!)

In the attributes inspector for the Navigation controller, uncheck the 'Shows Navigation Bar' option (this is a cosmetic change; I am assuming you don't need a navigation bar showing on the login screen !!)

就是这样:)

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

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