views:

27

answers:

2

Hi

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

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!!

A: 

Are you sure your chapterCount and pageCount views are not nil? You can have valid values all day, a message to nil does nothing and returns nil. Double check your view and controller wiring/unwiring when you change chapters.

EDIT:

confirm the size of the control is big enough to hold all your pages, and the view bounds is not clipped. For example, if you had 10 pages, and the "current" page was 10, but there were only 9 dots visible, it would appear as though nothing is highlighted because the white dot would be clipped from the visible area by being outside the viewable bounds. You can adjust the size dynamically using this:

- (CGSize)sizeForNumberOfPages:(NSInteger)pageCount
slf
Yes I have double checked (eg defined the variable again and also checked with NSLOG(@"%i"). When I check the documentation it says "Values outside the possible range are pinned to either 0 or numberOfPages minus 1." If I understand that right it means there will ALWAYS be a dot there.Just crazy...
Structurer
Just for fun I also tried to only have one UIPageControl, but still the same problem. Also tried adding a new UIPageControl in Interface Builder, and it shows exactly the same, erratic, behavior.
Structurer
Now double confirmed in Debugger (by hovering over the variable). So input is correct.I have this UIPageControl in a subView to the main view. Maybe I should refresh the view somehow??
Structurer
Thanks for the ideas. Made both UIPageControls as wide as the screen to check your theory. The number of dots is correct (5 and 10 as above picture) put the end dots (first left one and last right one) only shows correct the first time. Lets say I go chapter one page 1-10 then to chapter two. So far all show OK, but when I go back to chapter one page 10 (dot 10-1=9) it doesn't show. So frustrating...
Structurer
post all the code that switches between chapters, if you can, include how you are building the views
slf
A: 

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.

Structurer