Refresh Uipageviewcontroller - Reorder Pages and Add New Pages

Refresh UIPageViewController - reorder pages and add new pages

You need to call setViewControllers:direction:animated:completion:.

Also, in iOS 6, watch out if you're using UIPageViewControllerTransitionStyleScroll style, as there is a major caching bug if animated: is YES (see my discussion here: UIPageViewController navigates to wrong page with Scroll transition style).

How can I add new pages to a UIPageViewController after the user has reached the last page?

ssloan's answer was part of the key, but in my case simply calling setViewControllers:direction:animated:completion: in the network operation completion block wasn't enough (due to some edge cases).

My solution was to store the most recent view controller for which pageViewController:viewControllerAfterViewController: returned nil (I called it endPage) and to create a method...

- (void)fixAndResetEndPage {
if (self.endPage && self.endPage == self.currentPage) {
[self.pageController setViewControllers:@[self.currentPage] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.endPage = nil;
}
}

...which I called whenever my NSMutableArray of content controllers was mutated (e.g., network operation completion) and in pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted: whenever completed was YES.

UIPageViewController update number of pages

Use the UIPageViewController's setViewControllers method:

- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers 
direction:(UIPageViewControllerNavigationDirection)direction
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion;

Call this method on the UIPageViewController, and pass it the view controller you would like to present.

Reloading Views in UIPageViewController

After a long time and after wasting a support ticket with Apple, I decided to go with another approach.

In my Storyboard I created 2 different navigation controllers, one for each case (if there are somethings and if there aren't any), and I have an initial view Controller that, on viewDidAppear, instantiates one of the two and presents it. This way, I make sure that the entire navigation controller gets reloaded correctly.

UINavigationController *nc;

if ([Settings somethings].count)
{
nc = [self.storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
}
else
{
nc = [self.storyboard instantiateViewControllerWithIdentifier:@"NoSomethingNavigationController"];
}

self.nc = nc;

[self presentViewController:nc animated:NO completion:nil];

Keep previous pages in UIPageViewController

So no replies to this but this question has an upvote this time, I am assuming that someone might stumble into this problem.
So here is how I did it, I used 3 different UIPageViewControllers, for the front cover, the pages and for the back cover. This will get you to the point where the covers are visible when you are flipping through the pages.
Thanks.

Updating ViewController not updating PageViewController dots

I seem to have found one possible answer:

1st Question: How do I get the Page View Controller to properly update the dots on the bottom of the page. Rather than return 0, returning the current counter provides the right.

 func presentationIndex(for pageViewController: UIPageViewController) -> Int
{
return counter
}

2nd Question: How do I implement getting the current index? In my solution the counter variable identifies the current page. It doesn't properly get the index from the page shown but it works.

Implementation with the global counter variable is:

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?
{
let viewController = viewController as! SplashContentViewController
let index = viewController.pageIndex as Int

if(index == NSNotFound){
return nil
}
if(index > 0){
counter = index - 1
return self.pageTutorialAtIndex(counter)
} else {
counter = 0
return nil
}
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
{
let viewController = viewController as! SplashContentViewController
let index = viewController.pageIndex as Int
if((index == NSNotFound)){
return nil
}
if (index < pageImages.count - 1) {
counter = index + 1
return self.pageTutorialAtIndex(counter)
} else {
counter = pageImages.count - 1
return nil
}
}


Related Topics



Leave a reply



Submit