Removing a view controller from UIPageViewController

前端 未结 12 2535
梦谈多话
梦谈多话 2020-11-28 19:22

It\'s odd that there\'s no straightforward way to do this. Consider the following scenario:

  1. You have a page view controller with 1 page.
  2. Add another p
12条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 19:33

    Actually I think I solved the issue. This is what was happening in my app:

    1. UIViewController subclass instance was removed from UIPageViewController by removing it from model and setting viewControllers property of UIPageViewController to different ViewController. This is enough to do the job. No need to do any controller containment code on that controller
    2. The ViewController was gone, but I could still scroll to it by swiping right in my case.
    3. My issue was this. I was adding a custom gesture recognizer to ViewController displayed by UIPageViewController. This recognizer was hold as a strong property on the controller that also owned UIPageViewController.
    4. FIX: before loosing access to the ViewController being dismissed I made sure I properly cleaned all the memory it uses(dealloc) and removed the gesture recognizer
    5. Your mileage may vary, but I see no point for this solution to be wrong, when something's not working I first suspect my code :)

提交回复
热议问题