views:

888

answers:

3

What method to I use to make my UIScrollView update when the sides of a UIPageControl are tapped? When swiping the UIScrollView, the UIPageControl is updated correctly, but if I tap the sides of the UIPageControl to go to the next page, only the dots update, but the UIScrollView won't swipe. I've looked in the docs and am unable to find any methods for this?

If you're unsure of what I mean, go to your iPhone home screen and tap either side of the white dots, right between the dock and the paged icons.

+1  A: 

Just make sure you're giving your page control enough width, and you've hooked up its Value Changed outlet. If you do this, you should get messages when its value changes; look at the currentPage property on the control. It handles left- and right-margin taps properly.

Ben Gottlieb
Just to follow on from Ben's comment. Within your code handling the Value Changed event you can send your scroll view a scrollRectToVisible:animated: message. It is up to you to calculate the desired visible rect based upon page index. This calculation is obviously fairly easy if each of your pages is the same size.
Christopher Fairbairn
Thanks guys. I'm not using IB, where can I hook up the valueChanged event by code?
Canada Dev
Try using -[UIPageControl addTarget:action:forControlEvents].
Ben Gottlieb
Thanks, that did it.
Canada Dev
A: 

The method you're looking for is:

UIScrollView scrollRectToVisible: animated:

If you do this on the UIPageControl valueChanged, it should be automatic.

NWCoder
A: 

See my answer here: http://stackoverflow.com/questions/1103915/is-uipagecontrol-useless-by-itself/4014230#4014230

for a reusable class encapsulating the UIPageControl and UIScrollView.

Werner Altewischer