Skip to content

Instantly share code, notes, and snippets.

@0xced
Last active May 16, 2020 02:51
Show Gist options
  • Save 0xced/9929333 to your computer and use it in GitHub Desktop.
Save 0xced/9929333 to your computer and use it in GitHub Desktop.
Reload data workaround for UIPageViewController
#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)
- (void) xcd_setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL))completion;
@end
#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
@MrBoog
Copy link

MrBoog commented Nov 17, 2017

What do you think about this? looks like just another workaround, not sure which is better

- (void)reloadData
{
    self.pageViewController.dataSource = nil;
    self.pageViewController.dataSource = self.channelsDataSource;
}

@gerchicov-bp
Copy link

@MrBoog it doesn't work!

@cescobaz
Copy link

cescobaz commented Nov 3, 2018

I noticed that using animated = false is enough to "delete" the cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment