2

UIPageViewController で問題が発生しました。Coordinator のある時点で、UIViewControllers への参照が無効になります。モーダル ビューを閉じた後、最初のページを除くすべての UIPageViewController ページが失われます。

基本的な SwiftUI チュートリアルInterface with UIKitの完了として、タップで機能アイテムによって実装されたモーダル ビュー プレゼンテーション。github リポジトリがあります。

modalview が pageViewController デリゲートのコーディネーターを却下した後、最初に作成された UIViewControllers が数回再作成されている間に探していることがわかりました。そのため、ページをスクロールしようとすると、デリゲートは実際の 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 でモーダル ビューを使用するにはどうすればよいですか?

4

1 に答える 1