From 19de41148ad87ae1d26c32808a3dcc89a0e71348 Mon Sep 17 00:00:00 2001 From: Gustavo Gervasio Date: Tue, 29 Mar 2016 17:48:42 -0300 Subject: [PATCH] reloadData with currentIndex parameter --- .../FreeButtonsDemo/MBXFreeButtonsViewController.m | 2 +- .../LeftRightArrows/MBXLeftRightViewController.m | 8 ++++++-- .../MBXPageViewController/MBXPageViewController.h | 4 ++-- .../MBXPageViewController/MBXPageViewController.m | 11 +++++------ .../MBXSegmentControllerExampleViewController.m | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/MBXPageController/FreeButtonsDemo/MBXFreeButtonsViewController.m b/MBXPageController/FreeButtonsDemo/MBXFreeButtonsViewController.m index f42c032..02d14a3 100644 --- a/MBXPageController/FreeButtonsDemo/MBXFreeButtonsViewController.m +++ b/MBXPageController/FreeButtonsDemo/MBXFreeButtonsViewController.m @@ -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 diff --git a/MBXPageController/LeftRightArrows/MBXLeftRightViewController.m b/MBXPageController/LeftRightArrows/MBXLeftRightViewController.m index a64b858..6eded9f 100644 --- a/MBXPageController/LeftRightArrows/MBXLeftRightViewController.m +++ b/MBXPageController/LeftRightArrows/MBXLeftRightViewController.m @@ -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 @@ -85,4 +85,8 @@ - (void)MBXPageChangedToIndex:(NSInteger)index NSLog(@"%@ %ld", [self class], (long)index); } +-(void)MBXPageChanged { + NSLog(@"teste"); +} + @end diff --git a/MBXPageController/MBXPageViewController/MBXPageViewController.h b/MBXPageController/MBXPageViewController/MBXPageViewController.h index 93375b3..243b465 100644 --- a/MBXPageController/MBXPageViewController/MBXPageViewController.h +++ b/MBXPageController/MBXPageViewController/MBXPageViewController.h @@ -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 diff --git a/MBXPageController/MBXPageViewController/MBXPageViewController.m b/MBXPageController/MBXPageViewController/MBXPageViewController.m index 2402e31..cb539d7 100644 --- a/MBXPageController/MBXPageViewController/MBXPageViewController.m +++ b/MBXPageController/MBXPageViewController/MBXPageViewController.m @@ -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]; @@ -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]; @@ -74,7 +73,7 @@ - (void)moveToViewNumber:(NSInteger)viewNumber } [self setViewControllers:@[viewController] direction:direction - animated:YES + animated:animated completion:^(BOOL finished) { if (!weakSelf) return; @@ -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]; } diff --git a/MBXPageController/UISegmentController/MBXSegmentControllerExampleViewController.m b/MBXPageController/UISegmentController/MBXSegmentControllerExampleViewController.m index 585f095..7d8aabe 100644 --- a/MBXPageController/UISegmentController/MBXSegmentControllerExampleViewController.m +++ b/MBXPageController/UISegmentController/MBXSegmentControllerExampleViewController.m @@ -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]; }