将数据从 child 控制器传递到 PageViewController

Pass data from child controller to PageViewController

我有一个 PageViewcontroller 有 3 个 child 控制器。我想将数据从 first child 传递到 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



}

这是我的 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)



}

当我 select 来自 collectionview 的一个单元格时,我想将 isSelectAnything 值更改为 true 但它总是 return false.I 搜索但找不到任何解决方案。

我尝试了协议,但它再次不起作用

改变

let sendData = RootViewController()

let sendData = parent as! RootViewController