在容器视图中快速访问和更新tableview [英] Swift accessing and updating tableview in container view
问题描述
这有点令人困惑,但我会尽力解释.我有一个带有容器视图的视图控制器.在容器视图中是表格视图.我想从主视图控制器更新tableview.例如,表视图将包含名称列表.当用户在文本字段中输入名称时,表视图将更新以查找与用户输入内容匹配的名称.
This is kind of confusing but I will do my best to explain. I have a view controller with a container view. In the container view is a table view. I want to update the tableview from the main view controller. For example, the table view will contain a list of names. As the user types in a name into a text field, the table view will update to find names that match what the user inputed.
主要问题是:
如何从主视图控制器更新表视图?
How can I update the table view from the main view controller?
注意:由于数据会发生变化,因此我无法使用准备进行安全检查".
Note: I can't use prepare for segue because the data will be changing.
推荐答案
我知道了...
我可以通过childviewcontrollers访问该视图.这是我使用的代码:
I can access the view through childviewcontrollers. Here's the code I used:
let childView = self.childViewControllers.last as! ViewController
childView.List = self.nameList
childView.tableView.reloadData()
这篇关于在容器视图中快速访问和更新tableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!