ios - 调用通知时容器 View Controller 变量设置为默认值

标签 ios swift xcode uicontainerview

我有一个包含 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/

相关文章:

php - 适用于 iOS 的简单 PHP/MySQL Web 服务

ios - 如何在导航 Controller 中同时进行模式转换和弹出到根?

ios - 如何构建由 iOS 中现有控件组成的自定义控件?

iphone - 如何正确使用 nsoperationqueue 的 autoreleasepool

iOS 滑动抽屉

ios - React Native TabBarIOS.Item 中心图标

swift - 将缺失的三角形(工具提示)添加到标注自定义 MKAnnotationView 子类

swift - 如何将带参数的闭包传递给函数? ( swift )

xcode - 在 XCode 解决方案中使用 MonoDevelop C# 类

ios - 像 UITabBarItem 一样在 UIBarButtonItem 下添加标签