使用Swift在UIPageViewController子视图之间传递数据

Luk*_*uke 5 delegates uipageviewcontroller swift

我似乎无法找到直接困境的具体答案.

我有一个UIPageViewController以编程方式加载6个子UIView场景.它们托管了"添加"元素功能的各个阶段.目前,PageViewControllerClass将每个子视图添加到一个数组中,并在需要时将它们实例化为:

storyboard?.instantiateViewControllerWithIdentifier("editViewController")
Run Code Online (Sandbox Code Playgroud)

自然委托设置为在每个子场景之间滑动,因此不prepareForSegue运行" "功能.

当页面滑动时,实例化具有不同标识符的新场景.

从我的阅读中,我现在正在尝试设置一个代理,该代理接受一个Dictionary的实例,该代理读取/存储UIPageView进程的每个阶段(不同子场景)的输入并更新Dictionary.

我正在使用" viewWillDissapear"和" viewWillAppear"方法来帮助将传递数据设置到委托中.

不幸的是我遇到了问题,由于我缺乏经验,而且对这个具体问题不多,我需要帮助!

主要问题:

我可以在UIPageViewController课堂上设置一个数据代表,"会话"或儿童可以访问UIViews吗?

要么

有没有人知道将我的词典从孩子传给孩子的好方法????

A. *_*Vin 7

您可以从child-> parent-> child传递数据,而不是从child-> child传递数据.

首先,当您使用storyboard?.instantiateViewControllerWithIdentifier("editViewController")在PageViewController中实例化每个子节点时,保存对它的引用.

所以像

var firstViewController: EditViewController?
...
firstViewController = storyboard?.instantiateViewControllerWithIdentifier("editViewController") as EditViewController
Run Code Online (Sandbox Code Playgroud)

接下来,使用self.parentViewController在每个子ViewController中获取对PageViewController的引用.

var myPageViewController: PageViewContrller (or whatever yours is called) 
....
myPageViewController = self.parentViewController() as PageViewController (or whatever yours is called)
Run Code Online (Sandbox Code Playgroud)

现在,使用这两个引用,您可以在PageViewController和子节点中调用函数来来回传递数据.


Mar*_*anu 2

您应该在此处查看 UIPageViewController 委托。

您将获得在视图控制器之间转换之前和之后调用的这两个方法。

- pageViewController:willTransitionToViewControllers: // called before the transition starts
- pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted:  // called after the transition is finished
Run Code Online (Sandbox Code Playgroud)