使用StoryBoard的时候加入用户引导页面

如果想让一个APP加上引导页面是一个非常完美的举动

但是,总会遇到一些问题

(不要忘记在APDelegate里面加上用户引导页面的头文件和程序启动时的第一个页面哦)

情况一:纯代码

判断是否是第一次启动应用程序

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

{

    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]] ;

    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])

    {

         [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];

        NSLog(@"第一次启动");

    //如果是第一次启动的话,使用UserGuideViewController (用户引导页面) 作为根视图

     UserGuideViewController *userGuideViewController = [[UserGuideViewController alloc] init];

     self.window.rootViewController = userGuideViewController;

    }

    else

    {

       NSLog(@"不是第一次启动");

       

TranslateController *tranVC = [[TranslateController alloc] init];

           self.window.rootViewController = tranVC;


     }

         self.window.backgroundColor = [UIColor whiteColor];

         [self.window makeKeyAndVisible];

    return YES;

}



情况二:使用storyboard

情况基本相同,不同的是

 NSLog(@"不是第一次启动");

        UIStoryboard *story = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

        UIViewController * vc = [story instantiateViewControllerWithIdentifier:@"TranslateController"];

        self.window.rootViewController = vc;

解释一下原理先,如果使用纯代码的话,不是第一次启动应用程序的时候会自动执行下面的代码,所以不会有问题

如果使用storyboard的话,初始化第一个视图控制器(程序第一个界面),什么都没有,(除非你自己使用代码添加控件),而且storyboard在启动的时候并不是从这里开始的,而是默认storyboard的第一个视图控制器,所以,加上一个标志就好


这样它就能找到应该启动的界面


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值