0

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

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sergey M.
  • 1
  • 2
  • This might be helpful: http://stackoverflow.com/questions/17011579/add-a-child-view-controllers-view-to-a-subview-of-the-parent-view-controller – fiks Jul 19 '16 at 14:09
  • not sure that this can help me. I need that all controllers will be responsible to actions and would change size of parent containers. I can be wrong but in this example only one controller can work with it at the same time – Sergey M. Jul 19 '16 at 15:01

0 Answers0