I have a storyboard in Xcode5 where I have a UITabbarController that has a UINavigationController which is linked to a UIViewController. From that last UIViewController the rest (UIPageviewController and UITableViewController is created programmatically in the respective classes. See the screenshot.

The problem is setting the title of the UINavigationController when the page of the UIPageViewController changes. I want the title to reflect a @property on the UITableViewController class but I am not sure how to accomplish this.
I have already tried using an NSNotification set in the UITableViewController but there is no method which gets called every time the user swipes to left or right for another page (when using the scroll type). I guess if I have a place to put the NSNotification so that it gets called every time the users changes the page it solves my problem.
Hopefully someone can give me a pointer where to look or what method or delegate to use.
I had to do exactly this in the app I'm currently working on.
First ensure you have set self.pageViewController.delegate to self.
Here's what I did:
// Notice when the pageviewcontroller finishes animating between pages.
- (void)pageViewController:(UIPageViewController *)pageViewController
didFinishAnimating:(BOOL)finished
previousViewControllers:(NSArray *)previousViewControllers
transitionCompleted:(BOOL)completed {
// .viewControllers[0] is always (in my case at least) the 'current' viewController.
UIViewController* vc = self.pageViewController.viewControllers[0];
self.navigationItem.title = vc.navigationItem.title;
}
The 'secret' is that (at least in the simple swipe-left-right case with full-screen sized pages I have) that self.pageViewController.viewControllers[0] is the 'current' page.
To use your property rather than the navigationItem title, then just change the last line to something like self.navigationItem.title = ((MyViewController*)vc).myProperty;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With