【发布时间】:2018-10-04 23:54:12
【问题描述】:
我正在尝试使用 NEXT 按钮更改 UIPageViewController 的当前 ViewController。因此,我正在使用委托在 mainViewController 中调用我的 containerViewController 中的函数。但它不执行 setViewControllers 行。
在这里你可以看到我的代码:
这是我使用委托调用的方法:
func forwardPage() {
print("Start")
currentPage += 1
print(vcs[currentPage])
self.setViewControllers([vcs[currentPage]], direction: .forward, animated: true) { (true) in
print("Done")
}
}
这是我的代表:
protocol WalkthroughViewControllerDelegate {
func forwardPage()
func currentIndex() -> Int
}
这是连接到我的“下一步”按钮的功能:
@IBAction func nextButtonTapped(_ sender: Any) {
if let index = delegate?.currentIndex() {
print("Here... \(index)")
switch index {
case 0...1:
print("Forwarding...")
delegate?.forwardPage()
case 2:
dismiss(animated: true, completion: nil)
default: break
}
}
updateUI()
}
除了“完成”之外的所有内容都会打印出来
非常感谢您的帮助
我已经为此苦苦挣扎了一段时间
非常感谢:)
编辑:可能发生这种情况是因为 UIPageViewController 在 containerView 中。但我不确定
第二次编辑:我为这个问题创建了一个 git-hub 存储库。这是链接:https://github.com/LennartPhil/App-Popup-Screen。希望您能理解,我不会向您展示我的所有文件。
【问题讨论】:
-
“我正在调用容器视图控制器中的函数” ...
forwardPage()在您的UIPageViewController类中吗?换句话说,self是否有UIPageViewController的实例? -
而且...我使用嵌入在 containerView 中的页面视图控制器进行了测试,所以这不是问题(除非您的 func 位于错误的位置)。
-
是的,
self的类型是UIPageViewController -
嗯...不知道为什么你的代码不起作用。你有没有通过它来检查你的变量?我有一个简单的示例项目,它使用嵌入式页面视图控制器,以及以编程方式更改页面的按钮......并且尾随完成块 does 被调用。您可以看一下,并将我的方法与您的方法进行比较,看看是否有什么跳出来:github.com/DonMag/EmbeddedPageView
-
非常感谢您的帮助。不幸的是,我真的找不到任何可以帮助我的东西。但无论如何,我真的很感激 :)
标签: ios swift xcode uipageviewcontroller uicontainerview