Dynamically reload UIPageViewController after dataSource changed - ios

so I'm trying to create an ibooks-like reader and I need to update the contents of the UIPageViewController dynamically after I get the data from the webservice. For a long series of reasons I have to instantiate it at the beginning and then update it when the data comes.
I'm creating it like this:
NSDictionary *options =
[NSDictionary dictionaryWithObject:
[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin]
forKey: UIPageViewControllerOptionSpineLocationKey];
self.pageController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options: options];
self.pageController.dataSource = self;
self.pageController.delegate = self;
[[self.pageController view] setFrame:[[self view] bounds]];
MovellaContentViewController *initialViewController = [self viewControllerAtIndex:0];
self.controllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:self.controllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
and then I just set self.controllers = newControllersArray;
I'm looking for something like reloadData for a UITableViewController, is there such a thing for UIPageViewController?

You have to send setViewControllers:direction:animated:completion: to the pageController again
and give it the first view controller to display:
[self.pageController setViewControllers:[NSArray arrayWithObject:
[self viewControllerAtIndex:0]
]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
If viewControllerAtIndex:does not access self.controllers as I at first assumed, it should probably rather be
[self.pageController setViewControllers:[NSArray arrayWithObject:
[self.controllers objectAtIndex:0]
]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
instead

The main problem was that the webview was intercepting all the user touches and therefore the UiPageViewController wasn't calling the delegate methods. Once set the webview to ignore user touch events everything started to work properly.

Related

Add Custom View on UIPageViewController

I want to add a Custom View (red View) on the bottom of my UIPageViewController like this:
Because i want some Standard Text which is displayed on every View of my UIPageViewController. Everythings works fine, but my Custom VIew is not visible, this is what i tried:
- (void)viewDidLoad
{
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
FirstTutorialViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
//Here i try to set the Custom view:
[[self.pageController view] addSubview:[self customView]];
Don't add self customView to the page controller, and be sure to set its frame first.
Instead, resize the page controller to allow space at the bottom for the custom view and add both to your main view.

Delegate between UIViewControllers

I have following structure of ViewControllers:
PageViewController contains PhotoViewController and VideoViewController, that changing programmatically, so there no any segues.
I want allow VideoControlViewController to use methods from CameraViewController. I tried to use following code:
self.videoControlViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"videoControlViewController"];
self.videoControlViewController.delegate = self;
It don't works because method "instantiateViewControllerWithIdentifier" creates new instance of VideoViewController. Here is topic with the same problem that I found:
http://iphonedevsdk.com/forum/iphone-sdk-development/109543-string-becomes-nil-after-viewdidload-with-protocol-and-delegate.html
How can I point self.VideoControlViewController to its instance from storyboard if there no any segues or transitions?
- (void)viewDidLoad {
[super viewDidLoad];
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.viewControllers = #[#"photoControlViewController", #"videoControlViewController"];
self.pageViewController.dataSource = self;
[[self.pageViewController view] setFrame:[[self view] bounds]];
[self.pageViewController setViewControllers:[NSArray arrayWithObject:[self viewControllerAtIndex:[self.viewControllers indexOfObject:#"photoControlViewController"]]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[[self view] addSubview:[self.pageViewController view]];
[self.pageViewController didMoveToParentViewController:self];
}

Issue with iOS7 and UIPageViewController

I have a UIPageViewController that is added as subview on UIView. The UIView sits on the top of UIViewController's view, at start it puts the UIPageViewController lower than it should sit, but right after I click on the next button to push the next UIPageViewController's view, it send it back to the correct position.
What is he doing that? I tried everything but still can figure out the problem.
This is how it looks:
What seems to be the problem? Thanks in advance!
EDIT: This is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
DataChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageController.dataSource = self;
self.pageController.delegate = self;
self.pageController.view.userInteractionEnabled = NO;
self.pageController.view.frame = self.view.bounds;
[self.pageControllerParent addSubview:self.pageController.view];
[self addChildViewController:self.pageController];
self.currentPageControllerIndex = 1;
}
- (IBAction)buttonNextDidClicked
{
self.buttonNext.enabled = NO;
__weak typeof(self) __self = self;
[self.pageController setViewControllers:#[[self viewControllerAtIndex:self.currentPageControllerIndex]]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:^(BOOL finished) {
__self.currentPageControllerIndex++;
__self.buttonNext.enabled = YES;
}];
}
#pragma mark - UIPageViewControllerDelegate & DataSource
- (DataChildViewController *)viewControllerAtIndex:(NSUInteger)index
{
DataChildViewController *childViewController = [[DataChildViewController alloc] initWithNibName:#"DataChildViewController" bundle:nil];
childViewController.index = index;
return childViewController;
}
So, I've figured out the problem.
On viewDidLoad I had this line:
self.pageController.view.frame = self.view.bounds;
When it actually should be:
self.pageController.view.frame = self.pageControllerParent.bounds;

show UIViewController using UIPageViewController?

self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
MainScreenViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
This show me page like this
I want a new UIViewController on every movement of scrolling page. How can I do it?

uipageviewcontroller full screen

I am using the UIPageViewController. How do I make it so that each page of the controller is full screen. Right now I have images but it doesn't cover the full screen of the app. What can I do?
I am doing the following:
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
APPChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];

Resources