Melchior
Melchior

Reputation: 259

How do I implement configuration screen in a iOS app using Swift?

I'm new in developing iOS apps and I would like to know how can I implement views that appear only on first launch were the user can select his/her own language and nickname before starting the app? I try using navigation controller in my storyboard but no positive respond.

Thanks

Upvotes: 0

Views: 232

Answers (1)

egor.zhdan
egor.zhdan

Reputation: 4605

  1. Add a new UIViewController to your storyboard.
  2. Open identity inspector and fill the Storyboard ID like this: enter image description here
  3. Add this code to your main ViewController.swift file:

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
    
        let alreadyLogged = NSUserDefaults.standardUserDefaults().boolForKey("loggedIn")
        if !alreadyLogged {
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let configCtrl = sb.instantiateViewControllerWithIdentifier("configScreen")
            presentViewController(configCtrl, animated: true, completion: nil)
        }
    }
    
  4. When user finished the setup, do this:

    func finishedSetup() {
        NSUserDefaults.standardUserDefaults().setBool(true, forKey: "loggedIn")
        dismissViewControllerAnimated(true, completion: nil)
    }
    

Hope this helps.

Upvotes: 1

Related Questions