The goal is to have few views with own controllers (for example it can be view with PickerView, label and search text field) and main view with controller which will create these controllers.
I tryed to use StackView to add these controllers to the main view. The methods inside controllers invokes successfully but the stack view is empty.
Code of child control:
class LookupControl: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var picker: UIPickerView?
var pickerDataSource = ["t1", "t2", "t3"];
override func viewDidLoad() {
super.viewDidLoad()
picker?.dataSource = self
picker?.delegate = self
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerDataSource.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerDataSource[row]
}
}
Code of parent control:
class ContactDetailViewController: UIViewController, SubstitutableDetailViewController {
@IBOutlet var stackView: UIStackView?
override func viewDidLoad() {
super.viewDidLoad()
let lc = LookupControl(nibName: "LookupView", bundle: nil)
self.stackView?.addArrangedSubview(lc.view)
}
}
Is it posable to add UIViewControllers to StackView? What the best practice to do that in iOS?
Thanks in advance, Sergey