简体   繁体   中英

don't show again ViewController

In my app, I created a first ViewController (in storyboard) called welcome, with all the instructions. 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. 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]; NSString *testoSalvato = [[NSUserDefaults standardUserDefaults] objectForKey:@"ciao"]; if (testoSalvato == nil) { testo.text = @"Non hai ancora inserito il tuo nome"; } else { testo.text = [[NSString alloc] initWithFormat:@"Ciao %@", testoSalvato]; }

}

The IB Outlet is linked to a button

store the don't show again as a BOOL in NSUserDefaults .. and check it before showing the view..

if it is TRUE..dont show.other wise show it.

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)

then in your app delegate you have to get a 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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