使用Swift在UIPageViewController子视图之间传递数据
我似乎无法找到直接困境的具体答案.
我有一个UIPageViewController,它以编程方式加载6个子UIView场景.它们托管了“添加”元素功能的各个阶段.目前,PageViewController类将每个子视图添加到一个数组中,并在需要时实例化它们: storyboard?.instantiateViewControllerWithIdentifier("editViewController") 自然委托设置为在每个子场景之间滑动,因此不运行“prepareForSegue”功能. 当页面滑动时,实例化具有不同标识符的新场景. 从我的阅读,我现在正在尝试建立一个委托,该委托采用一个字典的实例,读取/存储该过程的每个阶段(不同的子UIPageView场景)的输入并更新字典. 我使用“viewWillDissapear”和“viewWillAppear”方法来帮助设置传递数据到委托中. 不幸的是我遇到了问题,由于我缺乏经验,而且对这个具体问题不多,我需要帮助! 主要问题: 我可以在UIPageViewController类中设置一个数据委托,“会话”或者可以由子UIViews访问吗? 要么 有没有人知道将我的词典从孩子传给孩子的好方法????
您可以从child-> parent->子项传递数据,而不是从child->子项传递数据.
首先,当您使用storyboard?.instantiateViewControllerWithIdentifier(“editViewController”)在PageViewController中实例化每个子节点时,保存对它的引用. 所以像 var firstViewController: EditViewController? ... firstViewController = storyboard?.instantiateViewControllerWithIdentifier("editViewController") as EditViewController 接下来,使用self.parentViewController在每个子ViewController中获取对PageViewController的引用. var myPageViewController: PageViewContrller (or whatever yours is called) .... myPageViewController = self.parentViewController() as PageViewController (or whatever yours is called) 现在,使用这两个引用,您可以在PageViewController和子节点中调用函数来来回传递数据. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |