简体   繁体   English

不再显示ViewController

[英]don't show again ViewController

In my app, I created a first ViewController (in storyboard) called welcome, with all the instructions. 在我的应用程序中,我创建了第一个名为Welcome的ViewController(在情节提要中),其中包含所有说明。 At the end of the page, I wanted to insert a box that could be selected showing "don't show again". 在页面末尾,我想插入一个可以选择显示“不再显示”的框。 By clicking on this box, and going to the next page, the first viewController will vanish. 通过单击此框,然后转到下一页,第一个viewController将消失。 When I reopen the app, the controller won't be shown again. 当我重新打开应用程序时,控制器将不再显示。 The only way to show it is by going on settings and selecting the switch "repristinate original settings" or something like that. 显示它的唯一方法是继续进行设置,然后选择“重新设置原始设置”之类的开关。 Please, can anyone help me? 拜托,有人可以帮我吗? Thanks! 谢谢!

I found an example but is not what I want: 我找到了一个例子,但不是我想要的:

- (IBAction)leggi{
NSString *stringaTesto = campo.text;
testo.text = [[NSString alloc] initWithFormat:@"%@", stringaTesto];

NSString *testoInserito = testo.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:testoInserito forKey:@"ciao"];
[defaults synchronize];

} }

- (void)viewDidLoad

{ [super viewDidLoad]; {[super viewDidLoad]; NSString *testoSalvato = [[NSUserDefaults standardUserDefaults] objectForKey:@"ciao"]; NSString * testoSalvato = [[NSUserDefaults standardUserDefaults] objectForKey:@“ ciao”]; if (testoSalvato == nil) { testo.text = @"Non hai ancora inserito il tuo nome"; 如果(testoSalvato == nil){testo.text = @“ Non hai ancora inserito il tuo nome”; } else { testo.text = [[NSString alloc] initWithFormat:@"Ciao %@", testoSalvato]; } else {testo.text = [[NSString alloc] initWithFormat:@“ Ciao%@”,testoSalvato]; } }

}

The IB Outlet is linked to a button IB插座链接到一个按钮

store the don't show again as a BOOL in NSUserDefaults .. and check it before showing the view.. 不再显示的内容作为BOOLNSUserDefaults ..中,并在显示视图之前进行检查。

if it is TRUE..dont show.other wise show it. 如果是TRUE,请不要显示。否则请显示它。

edit 编辑

Lets say you have your app delegate and currently show your don't show view again (Lets say A) from it ..after which you show another view(Lets say B) 假设您有您的应用程序委托,并且当前从中显示不显示视图(让我们说A),然后再显示另一个视图(让我们说B)

then in your app delegate you have to get a BOOL 然后在您的应用程序委托中,您必须获得BOOL

like this 像这样

BOOL _Dont_Show_Again = [NSUSerDefaults standardDefaults] boolForkey : @"Don't Show"];

if(_Dont_Show_Again)
{
load B Code here...
}
else
{
load A Code here;
}

first time _Dont_Show_Again will be 0 since it does not exist in default..but if user select don't show you should save it in the default and this code will then work fine for you _Dont_Show_Again第一次为0,因为默认情况下不存在。.但是,如果用户选择不显示,则应将其保存为默认值,然后此代码将对您有效

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

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