如何才能在首次发布时显示视图? [英] How can I show a view on the first launch only?

查看:92
本文介绍了如何才能在首次发布时显示视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Xcode 4.5和故事板构建了一个应用程序。应用程序第一次启动时,我希望初始视图控制器显示必须接受的条款和条件才能继续。之后,我希望应用程序启动并跳过第一个视图控制器并转到第二个。

I built an application using Xcode 4.5 with storyboards. The first time the app launches I want the initial view controller to appear with terms and conditions that must be accepted to proceed. After that, I want the app to launch and skip over the first view controller and go to the second one.

我知道我必须使用NSUserDefaults类和其他东西效果:
if([[NSUserDefaults standard ...] boolForKey:@iHaveAcceptedTheTerms])

I know I have to use the NSUserDefaults class and something to the effect of: if ([[NSUserDefaults standard...] boolForKey:@"iHaveAcceptedTheTerms"])

但我之前从未使用过这个类不知道如何实现此代码。有人可以分享如何做到这一点的具体细节吗?

But I have never used this class before and have no idea how to implement this code. Can someone share the specifics of how to do this?

推荐答案

你输入你的AppDelegate:

You put in in your AppDelegate:

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

//first-time ever defaults check and set
if([[NSUserDefaults standardUserDefaults] boolForKey:@"TermsAccepted"]!=YES)
{
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"TermsAccepted"];
}

然后在rootViewController中实现条款和条件以及接受它的方法。
您必须检查条款是否被接受,例如:

Then you implement in your rootViewController the terms and conditions and a way to accept it. You will have to check if the terms are accepted, for example like this:

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"TermsAccepted"]){
    //proceed with app normally
}
else{
//show terms
}

接受后,以下代码将更改默认设置:

When accepted, the following code will change the default settings:

 if(termsaccepted){
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TermsAccepted"];
}

这篇关于如何才能在首次发布时显示视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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