gpt4 book ai didi

swift - 如何在嵌入 ViewController 的容器 View 中设置 UIPageViewController 的委托(delegate)

转载 作者:行者123 更新时间:2023-11-28 15:27:24 24 4
gpt4 key购买 nike

我有一个 MainViewController,其中有一个容器 View ,其中嵌入了一个 UIPageViewControllerMainViewController 符合协议(protocol) UIPageViewControllerDelegate, UIPageViewControllerDataSource我希望嵌入的 UIPageViewControllerMainViewController 委托(delegate)。这可能吗?

基本上,我试图以类似的态度将 View Controller 中的 Collection View 作为 Storyboard 的导出,然后为其设置委托(delegate)(collectionView.delegate = self,假设 self 委托(delegate))所以这个态度用了一个UIPageViewController。我遇到的障碍是没有 PageView 作为 PageViewController 的对立面(与 Collection View 相比,我有 CollectionView 而不是 Collection View Controller

enter image description here

最佳答案

以下是您可以用来生成此内容的步骤:

您可以通过覆盖 MainViewController 中的 func prepare(for segue: UIStoryboardSegue, sender: Any?) 来获取对 UIPageViewController 的引用。当您的嵌入式 Controller 成为子 Controller 时,将触发此功能。

如果你给了你的 segue 一个名字(让我们使用 pageSegue 作为这个例子),你可以在 MainViewController 中做这样的事情:

func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "pageSegue", let controller = segue.destination as? UIPageViewController {
controller.delegate = self
controller.dataSource = self
}

}

关于swift - 如何在嵌入 ViewController 的容器 View 中设置 UIPageViewController 的委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45062702/

24 4 0
文章推荐: 带有返回字符串的iOS swift post方法
文章推荐: CSS:触发 标签中每个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com