【发布时间】:2019-12-03 22:34:37
【问题描述】:
我有一个 PageViewcontroller 有 3 个子控制器。我想将数据从第一个孩子传递给 Root PageViewController
这是我的根控制器。
我试过了:
class RootViewController: UIPageViewController ,UIPageViewControllerDataSource{
var isSelectAnything : Bool = false
func addRightBottom(sendBool : Bool){
self.isSelectAnything = sendBool
print(isSelectAnything) // always return false even I select a cell from my child
}
这是我的子控制器。
class FirstView: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
//There is a collectionview and this method works on :
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let sendData = RootViewController()
sendData.addRightBottom(sendBool: true)
}
当我从 collectionview 中选择一个单元格时,我想将 isSelectAnything 值更改为 true,但它总是返回 false。我搜索但找不到任何解决方案。
我尝试了协议,但它再次不起作用
【问题讨论】:
-
问题是
let sendData = RootViewController()。那是一个不同的 RootViewController。见programmingios.net/dont-make-a-new-instance-by-mistake
标签: swift uiviewcontroller uipageviewcontroller