I've got a UIPageControl
object working great in my app, except that I am not handling the default 'tap to advance/decrement' behavior.
I need to:
UIPageControl
is. I know I can capture the 'new' value on UIControlEventValueChanged
, but how would I know the 'old'? I manually setCurrentPage
in several places in my code, but saving the old state somewhere there could lead to bugs and is sort of a hack I think.
I don't think there is a property to keep the previous page, but why not define one? You can keep all the previous page numbers in an NSMutableArray
object and;
Whenever you want to come back a previous page, get the lastObject
of you array and remove it.
- (NSInteger)previousPageNumber { NSInteger pageNumber = 0; if(self.previousPagesArray.count > 0) { pageNumber = [[self.previousPagesArray lastObject] intValue]; [self.previousPagesArray removeLastObject]; } return pageNumber; }
and
-(void)goToNextPage
{
NSNumber *pageNumber = [NSNumber numberWithInt:self.pageControl.currentPage];
[self.previousPagesArray addObject:pageNumber];
//go to next page
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.