简体   繁体   English

如何仅在iOS中首次启动时显示视图控制器

[英]How can I show a view controller on the first launch only in ios

I just want to show an operator screen with three operators on the first time when app launches and if i did not selected any operator and i closed the app and again when i open the app i should see that operator screen only but i am going to home view controller. 我只想在应用程序启动时第一次显示一个由三个操作员组成的操作员屏幕,如果我没有选择任何操作员,并且我关闭了该应用程序,而当我打开该应用程序时,我应该只看到那个操作员屏幕,但是我要主视图控制器。 This is my code: 这是我的代码:

Home ViewController.m 主页ViewController.m

if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults]
                            objectForKey:@"aValue"]])
{
    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"aValue"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    //Action here

    UIViewController *myController = [self.storyboard instantiateViewControllerWithIdentifier:@"Operator"];
    [self.navigationController pushViewController: myController animated:YES];


}
 else
 {
 //self.view.backgroundColor = [UIColor redColor];


 }

Any changes to my code so that i can get the desired result. 对我的代码进行任何更改,以便我可以获得所需的结果。 Thanks in advance.... 提前致谢....

This code 这段代码

[[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"aValue"];
[[NSUserDefaults standardUserDefaults] synchronize];

should be moved into the view controller in which the user selects the operator. 应该被移到用户选择操作员的视图控制器中。 This should be done after the operator is selected and just before dismissing the operator view controller. 这应该在选择操作员之后且在解雇操作员视图控制器之前完成。

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

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