R.Ham R.Ham - 7 months ago 65
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")


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.