我有一个包含 TableView 的容器 View Controller 。在父 View Controller 中,我使用下面的代码访问容器 View 以设置一些变量并发送通知以重新加载 TableView 。但是当容器 View 收到来自父级的通知时,它会将所有变量设置为默认值,并且不会将任何内容加载到表中:
在父 View Controller 中:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let containerVC= storyboard.instantiateViewController(withIdentifier:"detailContainerVC") as! ContainerViewController
// self.navigationController?.pushViewController(containerVC,
// animated: false)
containerVC.section1RowCount = self.basicDataCount
containerVC.section2RowCount = self.checkDataCount
containerVC.GroupDetail = self.GroupDetail
containerVC.price = self.price
//containerVC.detailTable.reloadData()
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "fillDataDetail"), object: nil)
那么如何在父 View Controller 中设置这个容器 View 变量呢?
最佳答案
我通过在通知中使用 userInfo 发送参数来解决我的问题
关于ios - 调用通知时容器 View Controller 变量设置为默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47646995/