如何在iOS中启动应用程序之前打开ViewController [英] How to open a ViewController before application starts in iOS

查看:89
本文介绍了如何在iOS中启动应用程序之前打开ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 5中工作,在加载我的应用程序之前,我想打开另一个视图控制器,用户应该输入一些数据,例如.password,当密码匹配时,应用程序将被打开,我是没有得到如何做到这一点..我尝试了一些代码,我在下面写了

I am working in iOS 5,and before loading my application,I want to open a another view controller,where the user should enter some data,for eg.password and when the password matches ,application will be opened,I am not getting how to do this..I tried some code ,which I have written below

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    if(somecondition)
    {       
        ViewController *View =[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil]; 
        [_window addSubview:View.view];
    }

    return YES;
}

但我不知道这是否正确,所以朋友们,请帮助我出去..

But I dont know whether it is a right way,so friends,please help me out..

问候
Ranjit

Regards Ranjit

推荐答案

你可以创建一些 bool 变量来检查这是第一个开始还是另一个。存储此 bool 的最佳位置是NSUserDefaults。好吧,如果这是第一次启动,那么显示你的LoginViewController,如果没有 - 执行常规代码:

You can create some bool variable for checking is this a first start or another. The best place to store this bool is NSUserDefaults. Well, if this is a first start then show your LoginViewController, if not - execute regular code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    UIViewController *startVC = nil;

    if (isFirstLaunch){
        startVC = [[[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil] autorelease];
    }
    else{
        startVC = [[[WorkspaceViewController alloc] initWithNibName:@"WorkspaceView" bundle:nil] autorelease];
    }

    navController = [[UINavigationController alloc] initWithRootViewController:startVC];

    [self.window makeKeyAndVisible];
    [self.window addSubview:navController.view];

    return YES;
}

这篇关于如何在iOS中启动应用程序之前打开ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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