Skip to content

Instantly share code, notes, and snippets.

@0xced
Last active May 16, 2020 02:51

Revisions

  1. 0xced revised this gist Apr 2, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions UIPageViewController+ReloadData.h
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #import <UIKit/UIPageViewController.h>

    // Because UIPageViewController somehow "caches" its view controllers when you pass animated:YES and there is no "reloadData" method in UIPageViewControllerDataSource

    @interface UIPageViewController (ReloadData)
  2. 0xced created this gist Apr 2, 2014.
    7 changes: 7 additions & 0 deletions UIPageViewController+ReloadData.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // Because UIPageViewController somehow "caches" its view controllers when you pass animated:YES and there is no "reloadData" method in UIPageViewControllerDataSource

    @interface UIPageViewController (ReloadData)

    - (void) xcd_setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL))completion;

    @end
    16 changes: 16 additions & 0 deletions UIPageViewController+ReloadData.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #import "UIPageViewController+ReloadData.h"

    @implementation UIPageViewController (ReloadData)

    - (void) xcd_setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL))completion
    {
    void (^reloadData)(BOOL) = ^void(BOOL finished) {
    dispatch_async(dispatch_get_main_queue(), ^{
    [self setViewControllers:viewControllers direction:direction animated:NO completion:completion];
    });
    };

    [self setViewControllers:viewControllers direction:direction animated:animated completion:animated ? reloadData : completion];
    }

    @end