Search code examples
iosipaduisplitviewcontroller

SplitViewController: Pass data to DetailVC on first load/show


In this current SplitViewController constellation the MasterVC performs an operation/calculation in viewWillAppear. The result of that operation is needed in the DetailVC to load its view properly (the DetailVC has a table view).

I don't know how the loading/appearing sequence in a SplitViewController is (and how reliable it might be if known), but is it possible to

  1. Perform the operation/calculation in the MasterVC on viewWillAppear
  2. Pass the information to the DetailVC (either using the properties of DetailVC or with a protocol)
  3. DetailVC will be loaded when the required information is available (e.g. viewWillLoad/viewWillAppear of DetailVC)?

Solution

  • Both the master and detail viewDidLoad methods are called at start up with a split view controller. So, you can't control when the detail controller gets loaded based on something happening in the master view controller. The detail view controller's viewWillAppear is called before the master's viewWillAppear since you only see the detail view at start up (in portrait orientation). So, you probably need to have a placeholder view in the detail view controller, if you want something to appear there before the master controller does its calculation.

    This is only true if the iPad is in portrait orientation when the app starts. If you have it turned to the landscape orientation when you start the app, then you get the viewDidLoad and viewWillAppear of the master before either of those methods gets called in detail.