Lets assume we have ten pages.
An event handler for the event is added as below:
Run the app. Now in the ten pages, by default page 1 (index 0) is selected. Touch the second page or third page. The event wont be triggered. If the last page is selected, the event will be triggered. The same happens with last page. Once you have selected the last page, select the previous page. The event will not be triggered, but if you select the first page, the event will not be triggered.
To see an easy demonstration of this case, download the UICatalog example and open the ControlsViewController.m and change the UIControlEventTouchUpInside to UIControlEventValueChanged in line no 375.
- (UIPageControl *)pageControl
{
if (pageControl == nil)
{
CGRect frame = CGRectMake(120.0, 14.0, 178.0, 20.0);
pageControl = [[UIPageControl alloc] initWithFrame:frame];
[pageControl addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
// in case the parent view draws with a custom color or gradient, use a transparent color
pageControl.backgroundColor = [UIColor grayColor];
pageControl.numberOfPages = 10; // must be set or control won't draw
pageControl.currentPage = 0;
pageControl.tag = kViewTag; // tag this view for later so we can remove it from recycled table cells
}
return pageControl;
}