gdm
gdm

Reputation: 7978

UIPageViewController inside a custom UIViewController

I am stucked with this problem for all the afternoon. I made a custom UIViewController. Up to now I shown custom views inside this custom viewcontroller. All fine. Now what I want to do is to show a pageviewcontroller inside the custom controller. No error, but the view of the pagecontroller is shown outside the bounds of the custom controller (.

Here is my code

- (void)viewDidLoad
{
[super viewDidLoad];
self.monthYearController = [[avvAgendaMonthViewController alloc] init];
self.yearViewController  = [[avvAgendaYearViewController alloc] init];
self.pager               = [[UIPageViewController alloc]   initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
  navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                            options:nil];

//Assign the delegate and datasource .
self.pager.delegate = self;
self.pager.dataSource = self;

//Set the initial view controllers.
NSArray *viewControllers = [NSArray arrayWithObject:self.yearViewController];
[self.pager setViewControllers:viewControllers
            direction:UIPageViewControllerNavigationDirectionForward
            animated:NO
            completion:nil];



//Add the pageViewController as the childViewController
[self addChildViewController:self.pager];
[self.view addSubview:self.pager.view];

[self.pager didMoveToParentViewController:self];
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
self.pager.view.frame = pageViewRect;


//Assign the gestureRecognizers property of our pageViewController to our view's gestureRecognizers property.
self.view.gestureRecognizers = self.pager.gestureRecognizers;

And here is the interface (very simple):

@interface CustomNavigatorViewController : UIViewController      <CustomNavigationDelegate,UIPageViewControllerDataSource,UIPageViewControllerDelegate>

@property (nonatomic,strong) CustomNavigation* navigation;
@property (nonatomic,strong) UIPageViewController *pager;
@property (nonatomic,strong) AgendaYearViewController* yearViewController;
@property (nonatomic,strong) AgendaMonthViewController* monthYearController;
@property (nonatomic,strong) UIViewController* agendaCurrentView;


@end

I tried (as suggested in the first answer) to call didMoveToParentViewController at the end:

CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
self.pager.view.frame = pageViewRect;
[self.pager didMoveToParentViewController:self];

but no luck as the picture shows: the custom view controller is underneath the calendar view. The calendar view should be inside the custom view controller and not outside

the custom view controller is underneath the calendar view. The calendar view should be inside the custom view controller and not outside. Moreover, how can I put the spine on the top?

[SOLVED] Never mind: the first answer was right. My mistake was a wrong frame set.

Upvotes: 2

Views: 4519

Answers (1)

Engin Kurutepe
Engin Kurutepe

Reputation: 6747

I had the exact same problem. Setting the frame of the page view controller before calling didMoveToParentViewController: should resolve it.

Upvotes: 2

Related Questions