Search code examples
iphoneuipagecontrol

Erratic UIPageControls


I'm using two UIPageControls in a view to reflect chapters and pages. So I have defined one UIPageControl named chapterCount and one named pageCount just to show where the user is. I handle the flipping of the pages with swipes rather than using the UIPageControls (so no methods defined for them).

I change their values as the user change pages with the following code:

chapterCount.numberOfPages = chapters;
chapterCount.currentPage = chapterNumber;

pageCount.numberOfPages = pages;
pageCount.currentPage = pageNumber;

[chapterCount updateCurrentPageDisplay];
[pageCount updateCurrentPageDisplay];

Where chapters, chapterNumber, pages and pageNumber all are integers.

The first time I flip through the pages it normally works fine, but when I go to a previous chapter or start a new chapter, the first (or last depending on direction) dot is not showed. Please see picture (upper half is missing a dot, lower one OK).

alt text http://img80.imageshack.us/img80/3339/pagecontrol.png

Its the same code updating the controls and sometime I get a dot, sometimes not. When I check the variables with NSLOG they are correct (eg the same for both pictures above).

I have checked Apple's documentation and tried their example but no luck.

Where should I start troubleshooting? I'm getting crazy!!


Solution

  • I finally found the problem :-)

    An UIPageControl that is given a value 0 for number of pages will not show correctly the next time it is updated. I was reading chapter and page numbers from an array and in the beginning (let's say cover of the book) there are no pages and no chapters to show, so I happily set these to 0. Since I did not want to change the source data in my array I used MAX(pages , 1) for numberOfPages, so now it's working like clockwork.