0

I want that if you launch the App for the first Time, a certain UIView opens. But if you launch it later this UIView shouldn't be able to see.

How can I program this ?

I use Storyboards and I've setter up my view already in Storyboard.

Here is what I've already coded:

- (void)viewDidLoad {

    [super viewDidLoad];

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

        //View opens

        [[NSUserDefaults standardUserDefaults] setBool:YES 
                                              forKey:@"hasPerformedFirstLaunch"];
        [[NSUserDefaults standardUserDefaults] synchronize];

    } else {
        //RootView opens
    }    
// Do any additional setup after loading the view, typically from a nib.
}

So what can I enter at //View opens and //RootView opens? Thank you really much!

  • possible duplicate of [iPhone: How do I detect when an app is launched for the first time?](http://stackoverflow.com/questions/308832/iphone-how-do-i-detect-when-an-app-is-launched-for-the-first-time) – Carl Veazey May 24 '14 at 17:52
  • possible duplicate of [Perform Segue on ViewDidLoad](http://stackoverflow.com/questions/8221787/perform-segue-on-viewdidload) – markhunte May 24 '14 at 17:56

2 Answers2

0

You already prepared everything, you just have to show a specific UIView you want. Maybe you have it already created inside another class, then initialize it and add it to your main view, maybe like this.

MyUIViewExtension *viewExt = [MyUIViewExtension alloc] initWithFrame:....];
// add some other properties
[self.view addSubview:viewExt];

But it is up to you in which way a UIView will be shown.


To Add the UIView from the UIStoryboard, you have set an identifier. I would prefer to use the UIViewController name:

enter image description here

Inside your class, insert these lines of code:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" 
                                                     bundle:nil];
NSString *strVC = [NSString stringWithFormat:@"%@", [ViewController class]];
ViewController *viewController = 
  [storyboard instantiateViewControllerWithIdentifier:strVC];

Of course it would be better to create the ViewController as a Class variable so you can use it after creation.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
  • how can I just show a view controller that I've already set up in Storyboard? –  May 24 '14 at 18:50
0

Depends on what you really aim to do. If you just want to add a view within the regular view of your current view controller, then you can add it as suggested or simply unhide it and hide it otherwise. You may hide it per default in Interface Builder (resp. Storyboard Editor) or hide it in the else branch.

OR you can present a view controller. You could so by programmatically segueing to a segue that is defined (and named with an id) in your storyboard or you can present it using your navigation controller - if you have one - or you can present it modally. A modal presentation works regardless if you have a navigation controller or not. A modal presentation does not need to cover the full screen, but it may well do.

So - it depends.

Do not expect some really reasonable piece of code - reasonable in the context of your question - until you reveal what you prefer or at least how it should look like.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71