Skip to content

Commit

Permalink
Added delegate methods for will change page and did change page.
Browse files Browse the repository at this point in the history
  • Loading branch information
btate committed Aug 13, 2014
1 parent e8f5c29 commit d375b03
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions BTGridPager/BTGridPager.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ typedef NSUInteger BTGridResetMode;
*/
- (void) gridPager: (BTGridPager *) gridPager didSelectViewAtGridIndex: (BTGridIndex *) gridIndex;

/**
* Tells the delegate that the grid pager will change pages.
*
* @param gridPager The grid pager
* @param newIndex The page index
*/
- (void) gridPager: (BTGridPager *) gridPager willChangePage: (BTGridIndex *) newIndex;

/**
* Tells the delegate that the grid pager changed pages.
*
* @param gridPager The grid pager
* @param newIndex The page index
*/
- (void) gridPager: (BTGridPager *) gridPager didChangePage: (BTGridIndex *) newIndex;

@end

/**
Expand Down Expand Up @@ -144,4 +160,5 @@ typedef NSUInteger BTGridResetMode;
*/
- (UIView *) gridPager: (BTGridPager *) gridPager gridViewAtGridIndex: (BTGridIndex *) gridIndex withFrame: (CGRect) frame;


@end
7 changes: 7 additions & 0 deletions BTGridPager/BTGridPager.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ - (void) loadViewsForCurrentIndex{
NSAssert([self.gridPagerDataSource respondsToSelector:@selector(numberOfRowsInGridPager:)], @"Implement DataSource Methods!!!!!");
NSAssert([self.gridPagerDataSource respondsToSelector:@selector(gridPager:numberOfColumnsForRow:)], @"Implement DataSource Methods!!!!!");

if ([self.gridPagerDelegate respondsToSelector:@selector(gridPager:willChangePage:)]) {
[self.gridPagerDelegate gridPager:self willChangePage:[_currentIndex copy]];
}

_numRows = (int)[self.gridPagerDataSource numberOfRowsInGridPager:self];
if (_numRows <= 0)
return;
Expand Down Expand Up @@ -229,6 +233,9 @@ - (void) loadViewsForCurrentIndex{
[subview removeFromSuperview];
}

if ([self.gridPagerDelegate respondsToSelector:@selector(gridPager:didChangePage:)]) {
[self.gridPagerDelegate gridPager:self didChangePage:[_currentIndex copy]];
}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions BTGridPagerDemo/BTGridPagerDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ - (void) gridPager: (BTGridPager *) gridPager didSelectViewAtGridIndex: (BTGridI
NSLog(@"selected %@", gridIndex);
}

/**
* Tells the delegate that the grid pager will change pages.
*
* @param gridPager The grid pager
* @param newIndex The page index
*/
- (void) gridPager: (BTGridPager *) gridPager willChangePage: (BTGridIndex *) newIndex{
NSLog(@"will change pages %@", newIndex);
}

/**
* Tells the delegate that the grid pager changed pages.
*
* @param gridPager The grid pager
* @param newIndex The page index
*/
- (void) gridPager: (BTGridPager *) gridPager didChangePage: (BTGridIndex *) newIndex{
NSLog(@"on new page %@", newIndex);
}

#pragma mark - GridPagerDataSource

/**
Expand Down

0 comments on commit d375b03

Please sign in to comment.