ios - 具有不同 ViewController 的 UIPageViewController
<p><p>我想用 UIPageViewController 和拖曳按钮(下一个和上一个)来显示 7 个不同内容的 ViewController ,这是我实现 UIPageViewController 后的 Storyboard。 </p>
<p>我的问题是如何将这些 ViewController 放入 UIPageViewController 中? </p>
<p> <a href="/image/Gbcwd.png" rel="noreferrer noopener nofollow"><img src="/image/Gbcwd.png" alt=""/></a>
<a href="/image/7UzJK.png" rel="noreferrer noopener nofollow"><img src="/image/7UzJK.png" alt="page.xib"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>用 Swift 回答:</p>
<p>在 UIPageVC 实例的 viewDidLoad 中调用 setViewControllers 方法来定义您的第一个 VC、方向等:</p>
<pre><code>override func viewDidLoad() {
super.viewDidLoad()
dataSource = self
let vc = storyboard!.instantiateViewController(withIdentifier: "whatever storyboard id your first VC is")
setViewControllers(,
direction: .forward,
animated: false,
completion: nil)
}
</code></pre>
<p>使用 UIPageViewControllerDataSource 协议(protocol)方法来定义当前 viewController 之前和之后的页面以及 ViewController 计数和索引。</p>
<pre><code>func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController?
{
// Return some VC based on what the current viewController param is.
}
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController?
{
// Return some VC based on what the current viewController param is.
}
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return 7
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return viewControllers!.index(of: viewControllers!.first!)!
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 具有不同 ViewController 的 UIPageViewController,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42160419/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42160419/
</a>
</p>
页:
[1]