Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viewWillAppear causes controller to initialize again #27

Open
D-32 opened this issue Jul 17, 2015 · 1 comment
Open

viewWillAppear causes controller to initialize again #27

D-32 opened this issue Jul 17, 2015 · 1 comment

Comments

@D-32
Copy link

D-32 commented Jul 17, 2015

The setup code inside viewWillAppear should only be performed once. Inside my app it happens that I push a view controller and when navigating back viewWillAppear is called again. This then causes all the pages to be setup again and the current index is reset.

@nazywamsiepawel
Copy link

nazywamsiepawel commented Oct 17, 2016

hey there,

I have been facing the same issue and came up with a solution of quality proportional to the amount of time I had to investigate the issue. tl;dr - lame but works.

You need to change that :

-(void)viewWillAppear:(BOOL)animated {
    [self setupPageViewController];
    [self setupSegmentButtons];


    CGRect sizeRect = [UIScreen mainScreen].applicationFrame;
    float width = sizeRect.size.width;
    NSInteger xCoor = (width/[viewControllerArray count])*self.currentPageIndex-X_OFFSET;
    selectionBar.frame = CGRectMake(xCoor, selectionBar.frame.origin.y, selectionBar.frame.size.width, selectionBar.frame.size.height);
}

And then update the first view controller that is being loaded currentPageIndex.

-(void)setupPageViewController {
    pageController = (UIPageViewController*)self.topViewController;
    pageController.delegate = self;
    pageController.dataSource = self;
    [pageController setViewControllers:@[[viewControllerArray objectAtIndex:self.currentPageIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
    [self syncScrollView];
}

Not sure if it was a bug or by design but in my case pushing anything on top of the navigation and then going back was causing some rather unintuitive behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants