【发布时间】:2019-10-20 00:28:49
【问题描述】:
我在使用 UIPageViewController 时遇到了一些问题。在其 Coordinator 的某个时刻,对 UIViewControllers 的引用变得无效。它会导致关闭模式视图后除第一个页面外的所有 UIPageViewController 页面。
作为基本 SwiftUI 教程 Interfacing with UIKit 的完成,模态视图演示通过特色项目实现了点击。有github repo。
我发现在 modalview 解散 pageViewController 委托中的协调器后,会在重新创建几次时查找最初创建的 UIViewController。因此,当我尝试滚动页面时,代表找不到实际的 UIViewControllers
func pageViewController(
_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController?
{
guard let index = __parent.controllers.firstIndex(of: viewController)__ else {
return nil
}
}
正如官方文档所说,协调器和UIPageViewController的同步应该是UIViewControllerRepresentable的责任
/// Updates the presented `UIViewController` (and coordinator) to the latest
/// configuration.
func updateUIViewController(_ uiViewController: Self.UIViewControllerType, context: Self.Context)
我错过了什么还是 UIViewControllerRepresentable 中的这个错误?如何在 UIPageViewController 上使用模态视图而不失去滚动页面的能力?
【问题讨论】:
标签: swiftui uipageviewcontroller modal-view