1

I have this code in swift.

The code is supposed to load tutorial page for first comers and then navigate to MainStoryboard.

This if (controller is InlineMainViewController ){ used to return true but now it returns alwyas false

what can cause the main story board not to show? or to load different viewController?

I have check in the identity hierarchy that the storyboard is connected to InlineMainViewController uiViewController.

what else should I check?

  func chooseAndLuanchStoryboard(){
        Settings.registerDefaults()

        if( !Settings.groupDefaults().boolForKey(onboardingKey)) {
            launchStoryboard(Storyboard.OnboardingTofu)
        } else {
            launchStoryboard(Storyboard.Main)
        }
    }



func launchStoryboard(storyboard: Storyboard) {
    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Slide)
    let storyboard = UIStoryboard(name: storyboard.rawValue, bundle: nil)
    let controller = storyboard.instantiateInitialViewController()!
    if (controller is InlineMainViewController ){
        mainViewController = controller as! InlineMainViewController
    }
    window?.rootViewController = controller
    window?.makeKeyAndVisible()
}

1 Answer 1

0

Verify within your storyboard that the initial VC is , in fact, your InlineMainViewController. If your VC is embedded in a UINavigationController or UITabBarController, then it is possible that the initial VC is actually one of those classes or a subclass. Your Storyboard Enum, could you share the code? Is the type of raw value for each case String?

I would add this as a comment, but my account is too new.

5
  • The problem happens only why I add this attribute: @objc(ViewController) // match the ObjC symbol name inside Storyboard public class InlineMainViewController: UIViewController,
    – Elad Benda
    Feb 6, 2016 at 16:40
  • The (ViewController) after your @objc modifier tells objective-C what name to look for when it looks for that code, so it could be related to your issue. Also related, your Enum with string raw value cannot be seen by objective C. Feb 6, 2016 at 16:50
  • but it doesn't work even if i write "Main" instead of "storyboard.rawvalue"
    – Elad Benda
    Feb 6, 2016 at 16:59
  • Why do you assign both the window's rootVc and your property mainViewController the controller? Is it possible that you want to assign the mainViewController to the window.rootViewController ? The name after @objc(ViewController) means that objective-C will use that as a class name, not a string identifier. Can you remove the @objc? Are you in a mixed language project? Feb 6, 2016 at 17:05
  • You should update your code to this. if let controller = storyboard.instantiateInitialViewController() as? InlineMainViewController { window?.rootViewController = controller } else { fatalError(“Couldn’t load the required controller”) }
    – Pradeep K
    Feb 6, 2016 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.