1

I wanted to ad an option into my application to change the initial ViewController so users can skip the login view.

class SettingsViewController: UIViewController {

var vc: UIViewController?

@IBOutlet var changeInitialView: UISwitch?

@IBAction func changeButton(sender: UIButton) {
    if changeInitialView!.on {
        print("Switch is off")
        vc = UIStoryboard(name: "MenuViewController", bundle: nil).instantiateViewControllerWithIdentifier("MenuViewController")
        changeInitialView!.setOn(false, animated:true)
    } else {
        print("Switch is on")
        changeInitialView!.setOn(true, animated:true)
    }
}

if I try it like this, it always shows me this fail message: Could not find a storyboard named 'MenuViewController' in bundle ...

Moin Shirazi
  • 4,372
  • 2
  • 26
  • 38
Thobbit
  • 103
  • 9

1 Answers1

0

First VC is a UIViewController object and second I think MenuViewController is your viewcontroller's name not the storyboard name. Try following the below steps :

  1. Initially you must have an initial VC from where your app flow will start.
  2. Now if you want to change the initial VC when next time your app is launched, just create a flag and store its value in NSUserDefaults.
  3. in didFinishLaunchingWithOptions, check the flag in NSUserDefaults and accordingly set your initial VC.

The code for step 3, is shown in the link which I had shared earlier.

Ujjwal Khatri
  • 716
  • 1
  • 6
  • 19
  • Yeah I've also tried with the name in the storyboard ("Menu") but this doesn't work as well. What do you mean with vc is a UIViewController object? do I have to change there something? – Thobbit Mar 28 '16 at 11:21
  • what is storyboard name? – Ujjwal Khatri Mar 28 '16 at 11:23
  • The Storyboard name is "Menu" – Thobbit Mar 28 '16 at 11:24
  • http://stackoverflow.com/questions/10428629/programatically-set-the-initial-view-controller-using-storyboards, see if this can help you. – Ujjwal Khatri Mar 28 '16 at 11:26
  • Thx but now I get an error because it don't find the name of the first initial ViewController. It's just the same error then now but it shows allready when starting the app. Somehow I dont' write the right name, but I have tried the title as well as the ID – Thobbit Mar 28 '16 at 11:42
  • thanks for your help. but all I try also with the link you shared ends with the error _Could not find a storyboard named '...' in bundle ..._ – Thobbit Mar 28 '16 at 19:09