【问题标题】:Pass data from child controller to PageViewController将数据从子控制器传递到 PageViewController
【发布时间】: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。我搜索但找不到任何解决方案。

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

【问题讨论】:

标签: swift uiviewcontroller uipageviewcontroller


【解决方案1】:

改变

let sendData = RootViewController()

let sendData = parent as! RootViewController

【讨论】:

  • 我首先遇到了这个问题。谢谢回答。它有效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 2012-08-01
相关资源
最近更新 更多