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

时间:2019-12-03 22:34:37

标签: swift uiviewcontroller uipageviewcontroller

我有一个PageViewcontroller,有3个子控制器。我想将数据从第一个孩子传递到根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。我进行了搜索,但找不到任何解决方案。

我尝试了协议,但是没有再起作用

1 个答案:

答案 0 :(得分:1)

更改

let sendData = RootViewController()

收件人

let sendData = parent as! RootViewController
相关问题