Search code examples
iosxcodeuitableviewswift4uicontainerview

How to change properties of items in TableView through the ContainerView in Swift?


  • There is DetailedViewController (SelectedCell) on the left.
  • I want to make the detailed cell as table list of items.
  • Had an error due to static cells. (Static Cells should be inside TableView).

As a solution from StackOverflow to avoid this error:

  1. Created a container view inside the view.
  2. Deleted the connection and simple view on the right.
  3. Created TableView on the right and Embedded with Container View.

Problem: I have some values to display from the previous view, but I can't access these textFields on the right. (different class now).

Question: How to read/write data to/from the textFields with Container View?

enter image description here


Solution

  • Try to get the child view controllers of parent view controller (View controller that have container view in it) from there. From the child view controllers array cast your view controller (Which have your tableview in it) and make an instance.

    Using this instance you can change the properties of tableview.

    if let vcChild : ChildViewController = self.childViewControllers[0] as! ChildViewController { vcInfo.tableView.reloadData() }