1

(Xcode6-beta3, Swift, iPad, iOS8)

How can I create a splash page for an iPad app using a split view controller?

I've tried the straight-forward approach of drag n' dropping the little arrow to a new view controller, and setting up a button to segue to the split view controller on a touch up inside. This throws a memory error

I've also tried simply commenting out the following code from the application function in the AppDelegate, but I'm getting a *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [identifier length] > 0'

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {


// Override point for customization after application launch.

//        let splitViewController = self.window!.rootViewController as UISplitViewController
//        let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
//        splitViewController.delegate = navigationController.topViewController as DetailViewController

    return true
}

I've even disconnect the Master-Detail view in Storyboard, so that all that should be loaded is the splash page alone, but it still crashes.

I am so stuck! Thanks for your help.

kmiklas
  • 13,085
  • 22
  • 67
  • 103
  • Just created a new project using Single View Application template. Added Split view controller. Set segue from button to Split VC. Works. I'm not adding VC code. Can you share your project? – Diego Freniche Jul 17 '14 at 15:40
  • Ok... you've just become my personal hero. THANK YOU so much. If you want enter this as an answer I will mark it as accepted :D – kmiklas Jul 17 '14 at 15:47
  • For posterity, I created the app using the `Master-Detail Application` template. I then created a new view controller and inserted it before the Split view Controller Stuff. This was not working. – kmiklas Jul 17 '14 at 15:47
  • [Here](http://stackoverflow.com/questions/4213097/best-way-to-switch-between-uisplitviewcontroller-and-other-view-controllers/25979945#25979945) is how I handled this kind of situation, hope that helps. – tadija Sep 24 '14 at 08:55

1 Answers1

2

The problem you were having is related to the code in application:didFinishLaunchingWithOptions:

In that code the template access the "first" view controller defined in the Storyboard to get to the split view controller and set its delegate property. If you change the "little arrow" you are changing UIWindow's rootViewController property, and being of a different view controller, it crashes.

To solve that, the best way is:

  • create the storyboard as described (normal ViewController with a segue to the original Split VC)
  • comment out code in application:didFinishLaunchingWithOptions
  • create a UIView controller subclass for your newly added Scene
  • in that class, before the segue is done, insert this modified version of the code to set the Split View Controller's delegate property:

    let splitViewController = segue.destinationViewController as UISplitViewController
    
    let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
    
    splitViewController.delegate = navigationController.topViewController as DetailViewController
    

Working project here

Diego Freniche
  • 5,225
  • 3
  • 32
  • 45