timpone
timpone

Reputation: 19939

UIScrollView and issue setting UIPageControl's current page

I am trying to setup a UIPageControl and need to set the currentPage; I have the following but once the value is assigned self.pageControl.currentPage, it always equals 0 even though it should be a correct value. This is my first time using UIPageControl and I think I am missing something really basic; possibly always being reset to 0 somewhere. thx in advance

Here's my code

- (void)scrollViewDidEndDecelerating:(UIScrollView *)aScrollView
{
    self.pageControl.currentPage = (int) floor((self.scrollView.contentOffset.x + 0.25)/320.0f);
    int this_page=(int)(self.scrollView.contentOffset.x + 0.25)/320.0f;
  self.pageControl.currentPage=this_page;
  NSLog(@"here is property %d", self.pageControl.currentPage);
  NSLog(@"here is this_page %d", this_page);
  self.pageControl.currentPage=4;
  NSLog(@"here is property after manual set %d", self.pageControl.currentPage);

}

and my NSLog output.

2013-03-03 10:19:14.204 Lt[32045:11303] here is property 0
2013-03-03 10:19:14.206 Lt[32045:11303] here is this_page 1
2013-03-03 10:28:03.993 Lt[32209:11303] here is property after manual set 0
2013-03-03 10:19:15.449 Lt[32045:11303] here is property 0
2013-03-03 10:19:15.449 Lt[32045:11303] here is this_page 2
2013-03-03 10:28:03.993 Lt[32209:11303] here is property after manual set 0

Upvotes: 0

Views: 709

Answers (1)

matt
matt

Reputation: 534950

Most likely self.pageControl is nil, i.e. you never hooked up the outlet properly. Or else the page control itself isn't configured correctly, e.g. you never set numberOfPages.

BTW the easiest way to coordinate a page control with a paginating scroll view in iOS 6 is to use UIPageViewController instead.

Upvotes: 1

Related Questions