Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRASH: [UIPageControl] Page out-of-bounds. Requested 0 but the page control only has 0 pages: why?

My app has started reporting crashes with the error in the title. Had not seen this in the past year, and since I haven't changed any of my UIPageControl code, why the crashes?

like image 280
David H Avatar asked Nov 20 '25 23:11

David H


1 Answers

Searching, I only found a single hit on that string, from China. Translated, it says:

After iOS was updated to iOS14, the Run project would crash because the UIPageControl that I encapsulated crashed, but this did not happen in iOS13 and below. Finally, it was found that the crash was caused by assigning number before assigning Count

Yup! The app code was setting the number before the count! Posting this here so others hitting the same issue will know how to fix it quickly!

EDIT:

To be more precise:

if pageControl.numberOfPages > 0 {
    pageControl.currentPage = 0
}

Don't set the current page to anything if you don't have any pages yet!

like image 181
David H Avatar answered Nov 23 '25 03:11

David H