@@ -42,9 +42,6 @@ @interface SCPageViewController () <SCPageViewControllerViewDelegate, UIScrollVi
4242
4343@property (nonatomic , assign ) NSUInteger currentPage;
4444
45- @property (nonatomic , assign ) NSUInteger initialPage;
46- @property (nonatomic , assign ) BOOL finishedLoadingInitialPage;
47-
4845@property (nonatomic , strong ) NSMutableArray *visibleControllers;
4946
5047@property (nonatomic , assign ) BOOL isContentOffsetBlocked;
@@ -60,6 +57,8 @@ @interface SCPageViewController () <SCPageViewControllerViewDelegate, UIScrollVi
6057
6158@property (nonatomic , strong ) NSIndexSet *insertionIndexes;
6259
60+ @property (nonatomic , strong ) NSNumber *initialPageIndex;
61+
6362@end
6463
6564@implementation SCPageViewController
@@ -129,21 +128,19 @@ - (void)viewDidLoad
129128 [scrollViewWrapper addSubview: self .scrollView];
130129
131130 [self .view addSubview: scrollViewWrapper];
132-
133- if ([self .dataSource respondsToSelector: @selector (initialPageInPageViewController: )]) {
134- self.initialPage = [self .dataSource initialPageInPageViewController: self ];
135- self.currentPage = self.initialPage ;
136- self.finishedLoadingInitialPage = false ;
137- } else {
138- self.finishedLoadingInitialPage = true ;
139- }
140-
131+
132+ if ([self .dataSource respondsToSelector: @selector (initialPageInPageViewController: )]) {
133+ self.initialPageIndex = @([self .dataSource initialPageInPageViewController: self ]);
134+ self.currentPage = self.initialPageIndex .unsignedIntegerValue ;
135+ }
136+
141137 [self reloadData ];
142138}
143139
144140- (void )viewWillLayoutSubviews
145141{
146142 [super viewWillLayoutSubviews ];
143+
147144 [self setLayouter: self .layouter andFocusOnIndex: self .currentPage animated: NO completion: nil ];
148145}
149146
@@ -155,6 +152,13 @@ - (void)viewWillAppear:(BOOL)animated
155152 [self _tilePages ];
156153}
157154
155+ - (void )viewDidAppear : (BOOL )animated
156+ {
157+ [super viewDidAppear: animated];
158+
159+ self.initialPageIndex = nil ;
160+ }
161+
158162- (void )viewDidDisappear : (BOOL )animated
159163{
160164 [super viewDidDisappear: animated];
@@ -287,10 +291,6 @@ - (void)navigateToPageAtIndex:(NSUInteger)pageIndex
287291 if (completion) {
288292 completion ();
289293 }
290-
291- if (!self.finishedLoadingInitialPage && pageIndex == self.initialPage ) {
292- self.finishedLoadingInitialPage = true ;
293- }
294294 };
295295
296296 [self .scrollView setContentOffset: offset easingFunction: self .easingFunction duration: (animated ? self .animationDuration : 0 .0f ) completion: animationFinishedBlock];
@@ -472,9 +472,9 @@ - (void)_tilePages
472472 return ;
473473 }
474474
475- if (self.finishedLoadingInitialPage ) {
476- self.currentPage = [self _calculateCurrentPage ];
477- }
475+ if (! self.initialPageIndex ) {
476+ self.currentPage = [self _calculateCurrentPage ];
477+ }
478478
479479 NSInteger firstNeededPageIndex = self.currentPage - [self .layouter numberOfPagesToPreloadBeforeCurrentPage ];
480480 firstNeededPageIndex = MAX (firstNeededPageIndex, 0 );
0 commit comments