Skip to content

Commit

Permalink
Merge pull request #5 from gustavogervasio/animating
Browse files Browse the repository at this point in the history
reloadData with currentIndex parameter
  • Loading branch information
nicarq committed Apr 6, 2016
2 parents c4995d9 + 19de411 commit 5563eed
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ - (void)viewDidLoad {
// Initiate MBXPageController
MBXPageViewController *MBXPageController = [MBXPageViewController new];
MBXPageController.MBXDataSource = self;
[MBXPageController reloadPages];
[MBXPageController reloadPagesToCurrentPageIndex:0];
}

#pragma mark - MBXPageViewController Data Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ - (void)viewDidLoad {
self.MBXPageController.MBXDataSource = self;
self.MBXPageController.MBXDataDelegate = self;
self.MBXPageController.pageMode = MBX_LeftRightArrows;
[self.MBXPageController reloadPages];
[self.MBXPageController reloadPagesToCurrentPageIndex:0];
}

- (IBAction)goToThirdScreen:(id)sender {

[self.MBXPageController moveToViewNumber:2];
[self.MBXPageController moveToViewNumber:2 animated:true];
}

#pragma mark - MBXPageViewController Data Source
Expand Down Expand Up @@ -85,4 +85,8 @@ - (void)MBXPageChangedToIndex:(NSInteger)index
NSLog(@"%@ %ld", [self class], (long)index);
}

-(void)MBXPageChanged {
NSLog(@"teste");
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ typedef NS_ENUM(NSInteger, MBXPageMode) {

@property (nonatomic, assign) MBXPageMode pageMode; // This selects the mode of the PageViewController

- (void)reloadPages; // Like reloadData in tableView. You need to call this method to update the stack of viewcontrollers and/or buttons
- (void)moveToViewNumber:(NSInteger)viewNumber; // The ViewController position. Starts from 0
- (void)reloadPagesToCurrentPageIndex:(NSInteger)currentPageIndex; // Like reloadData in tableView. You need to call this method to update the stack of viewcontrollers and/or buttons
- (void)moveToViewNumber:(NSInteger)viewNumber animated:(BOOL)animated; // The ViewController position. Starts from 0
@end

@protocol MBXPageControllerDataSource <NSObject>
Expand Down
11 changes: 5 additions & 6 deletions MBXPageController/MBXPageViewController/MBXPageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

#pragma mark - Public

- (void)reloadPages
{
- (void)reloadPagesToCurrentPageIndex:(NSInteger)currentPageIndex {
// Initialize/ Refresh everything
self.currentPageIndex = currentPageIndex;
[self loadControllerAndView];
[self loadControllers];
[self connectButtons];
Expand All @@ -61,8 +61,7 @@ - (void)otherConfiguration {
// Replace me
}

- (void)moveToViewNumber:(NSInteger)viewNumber
{
- (void)moveToViewNumber:(NSInteger)viewNumber animated:(BOOL)animated {
NSAssert([_viewControllerArray count] > viewNumber, @"viewNumber exceeds the number of current viewcontrollers");
id viewController = _viewControllerArray[viewNumber];
[self MBXPageChangedToIndex:_currentPageIndex];
Expand All @@ -74,7 +73,7 @@ - (void)moveToViewNumber:(NSInteger)viewNumber
}
[self setViewControllers:@[viewController]
direction:direction
animated:YES
animated:animated
completion:^(BOOL finished) {

if (!weakSelf) return;
Expand Down Expand Up @@ -158,7 +157,7 @@ - (void)setupPageViewController

_pageController.delegate = self;
_pageController.dataSource = self;
[_pageController setViewControllers:@[[_viewControllerArray objectAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[_pageController setViewControllers:@[[_viewControllerArray objectAtIndex:_currentPageIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self syncScrollView];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ - (void)viewDidLoad {
self.MBXPageController.MBXDataSource = self;
self.MBXPageController.MBXDataDelegate = self;
self.MBXPageController.pageMode = MBX_SegmentController;
[self.MBXPageController reloadPages];
[self.MBXPageController reloadPagesToCurrentPageIndex:0];
}

- (IBAction)goToThirdView:(id)sender {

[self.MBXPageController moveToViewNumber:2];
[self.MBXPageController moveToViewNumber:2 animated:true];
}


Expand Down

0 comments on commit 5563eed

Please sign in to comment.