使用Swift在UIPageViewController子视图之间传递数据 [英] Passing data between UIPageViewController Child views with Swift
问题描述
我似乎无法找到解决我直接困境的具体答案。
I cant seem to find a specific answer to my direct dilemma.
我有一个 UIPageViewController
,该程序通过6个子 UIView $ c $加载c>场景。它们包含添加元素功能的各个阶段。当前,
PageViewController
类将每个子视图添加到数组中,并在需要时使用以下方法实例化它们:
I have a UIPageViewController
that programmatically loads through 6 child UIView
scenes. They host various stages of an 'add' element functionality. Currently the PageViewController
Class adds each child view into an array and instantiates them when required with:
storyboard?.instantiateViewControllerWithIdentifier("editViewController")
已建立自然委托人可以在每个子场景之间滑动,因此没有运行 prepareForSegue
函数。
The natural delegate is set-up to swipe between each child scene and therefore no "prepareForSegue
" function is run.
在滑动页面时,
根据我的阅读,我现在试图建立一个接受Dictionary实例的委托,该委托读取/存储输入。从该过程的每个阶段(不同子项 UIPageView
场景)开始,并更新字典。
From my reading, I am now attempting to set-up a delegate that takes an instance of a Dictionary, that reads/stores input from each stage (different child UIPageView
scenes) of the process and updates the Dictionary.
我正在使用 viewWillDissapear
和 viewWillAppear
方法可帮助设置将数据传递到委托中。
I am using the "viewWillDissapear
" and "viewWillAppear
" methods to help set-up the passing data into the delegate.
不幸的是,我遇到了问题,由于缺乏经验,在这个特定问题上的知识还不够多,我需要帮助!
Unfortunately I am running into problems, and due to my lack of experience, and not much on this specific problem, I'm needing help!
主要问题:
我可以在 UIPageViewController
类,该对话或子元素 UIViews
?
Can I set-up a data delegate in the UIPageViewController
class, that 'talks' or can be accessed by the child UIViews
?
OR
有人知道将我的词典从一个孩子传到另一个孩子的好方法吗??
Does anyone know of a good solution to pass my Dictionary from child to child to child????
推荐答案
您可以从child-> parent-> child传递数据,而不是从child-> child传递数据。
Instead of passing data from child->child, you could pass it from child->parent->child.
首先,在实例化每个对象时带有 storyboard?.instantiateViewControllerWithIdentifier( editViewController)的PageViewController中的子项,保存对其的引用。
First, when you instantiate each child in the PageViewController with storyboard?.instantiateViewControllerWithIdentifier("editViewController"), save a reference to it.
所以类似
var firstViewController: EditViewController?
...
firstViewController = storyboard?.instantiateViewControllerWithIdentifier("editViewController") as EditViewController
接下来,使用 self.parentViewController 在每个子ViewController中获得对PageViewController的引用。
Next, get a reference in each child ViewController to the PageViewController using self.parentViewController.
var myPageViewController: PageViewContrller (or whatever yours is called)
....
myPageViewController = self.parentViewController() as PageViewController (or whatever yours is called)
现在,使用这两个引用,您可以调用PageViewController和子级中的函数来回传递数据。
Now, using those two references, you can call functions in the PageViewController and in the children to pass data back and forth.
这篇关于使用Swift在UIPageViewController子视图之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!