Last active
May 16, 2020 02:51
-
-
Save 0xced/9929333 to your computer and use it in GitHub Desktop.
Reload data workaround for UIPageViewController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed that using
animated = false
is enough to "delete" the cache.