R.Ham R.Ham - 1 year ago 118
iOS Question

Swift: How to make a scroll view execute child view controllers viewDidLoad

I have a main menu view controller which hosts a scroll view containing 4 different child view controllers which are selected using XLPagerTabStrip (effectively a tab bar). The viewDidLoad of each child controller is only executed the first time one of the child view controllers is loaded within the main menu, but I want it to execute every time each child view controller is loaded.

Code that instantiates the view controllers within the main menu:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let childOneVC = storyboard.instantiateViewControllerWithIdentifier("childOne")

Answer Source

viewDidLoad is called only once in the lifecycle of UIViewController if you want it to be called again you will have to reinitialise the controller or else you can use other lifecycle methods like viewWillAppear or viewDidAppear which will be called every time the controller's view appears on screen.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download