I have an Assertion Failure in UIPageViewController.
Assertion failure in -[UIPageViewController _flushViewController:animated:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.12/UIPageViewController.m
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'Don't know about flushed view <UIView: 0x15a5bff30; frame = (0 0; 768 903); autoresize = W+H; layer = <CALayer: 0x15a5bfc30>>'
*** First throw call stack:
(0x181ebedb0 0x181523f80 0x181ebec80 0x182844154 0x1877a1c40 0x1877a1da8 0x18784e9c4 0x18784ebfc 0x187852318 0x18784dd98 0x1870101e4 0x1849a2994 0x18499d5d0 0x1870270a4 0x10028b620 0x100348b78 0x100379f54 0x100168878 0x18733d568 0x1870330b4 0x1870f1a00 0x18733e71c 0x1870f832c 0x18703536c 0x18700f7ac 0x18700ed40 0x18700eba8 0x1873283b4 0x18700d5e8 0x18784ebd4 0x187852318 0x18784df3c 0x1871db550 0x1871daf6c 0x101c9b768 0x1849f0234 0x1849f00e8 0x182135e54 0x181e5d030 0x181e757d4 0x181e74f0c 0x181e72c64 0x181d9cc50 0x183684088 0x18707e088 0x10033b200 0x18193a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
I don't know why this error is occurring. Any clues on what's causing it or how to debug it?
Move your
pageViewController.setViewControllers
function call insideDispatchQueue.main.async
block if you are doing it in code.I don't know why it works but it worked for me. For reference.
This happened to me too when I had textfields in child controller and didn't dismiss keyboard on scroll to next controller. If this is case just add endEditing in action where you programmatically change your controller or if you are scrolling on scrollViewDidScroll delegate method of pageViewController
For me, the issue was using
self.pageViewController
as a member of the current view controller instead ofpageViewController
as parameter obtained in thedidFinishAnimating
delegate method.The direct way to run into this assert is to use cycled source for
UIPageController
defined with scroll transition style.When the source contains two pages each one is the previous and the next for another one. If you swipe
UIPageController
containing two pages and then try to set source with 3 pages you will get the assertion mentioned above with guarantee assuming thatUIPageControllerDataSource
before/after methods allow cycled transition in case of 2 pages.The main rules of crash-free using
UIPageController
with scroll transition:1) set
dataSource
before callingsetViewControllers
method2) use
setViewControllers
method without animation (animated: false
)3) set
dataSource
to nil for single page mode4) don't allow cycles for 2-page mode
All these recommendations together make
UIPageController
absolutely stable.The overall implementation and usage examples one can find at GitHub project.
When
UIPageViewController
transition, ViewController inside it(ex: UITableViewController) transition will cause crash.In my case (crash):
step1
step2
Scroll the tableView while
UIPageViewController
transition.My Solution
(disable scroll both target view controller and current view controller)
This happens when your
UIPageViewControllerTransitionStyle
is set toscroll
instead ofpageCurl
.Are you dynamically creating View Controllers and setting them on UIPageViewController? In that case, you must ensure that the second call to setViewControllers is called after the first one completes animation because of a bug in UIKit. A delayed dispatch is a quick and dirty fix, though it is not a good practice
More details here.
https://forums.developer.apple.com/thread/6554