Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

GeorgeMincila

macrumors newbie
Original poster
Feb 24, 2011
3
0
I am using the page based application template from xcode that creates a RootViewController, a DataViewController and a ModelController.

I have managed to make it go to what ever page I need, from the RootViewController, but I also need this from the DataViewController, triggered on an event from a specific page. That does not work so well. How should I change the code for it to work from DataViewController?

My code looks like this: -from root(working):

PHP:
//get current index of current page
DataViewController *theCurrentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSUInteger retreivedIndex = [self.modelController indexOfViewController:theCurrentViewController];

//get the page(s) to go to
DataViewController *targetPageViewController = [self.modelController viewControllerAtIndex:(pageToGoTo - 1) storyboard:self.storyboard];

//put it(or them if in landscape view) in an array
NSArray *theViewControllers = nil;
theViewControllers = [NSArray arrayWithObjects:targetPageViewController, nil];

//check which direction to animate page turn then turn page accordingly
if (retreivedIndex < (pageToGoTo - 1) && retreivedIndex != (pageToGoTo - 1)){
[self.pageViewController setViewControllers:theViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL]; 
} 
if (retreivedIndex > (pageToGoTo - 1) && retreivedIndex != (pageToGoTo - 1)){
[self.pageViewController setViewControllers:theViewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:NULL];
}

-from a page, dataviewcontroller(not working):

PHP:
DataViewController *targetPageViewController = [((UIPageViewController*)self.parentViewController) viewControllerAtIndex:(pageToGoTo - 1) storyboard:self.storyboard]; //The problem is here, but I do not know how to solve it.


//put it(or them if in landscape view) in an array
NSArray *theViewControllers = nil;
theViewControllers = [NSArray arrayWithObjects:targetPageViewController, nil];


[((UIPageViewController*)self.parentViewController) setViewControllers: theViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.