Button in UIPageViewController

I want to add a UIButton to my UIViewController. I have a UIPageViewController on all screens. When I try to add this button ... there is no button on the screen. What am I doing wrong?

CODE:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self
               action:@selector(setButtonVisibleClose:)
     forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"Zamknij widok" forState:UIControlStateNormal];
    button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
    button.backgroundColor = [UIColor whiteColor];
    [self.view addSubview: button];


    self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

    self.pageController.dataSource = self;
    [[self.pageController view] setFrame:[[self view] bounds]];

    BasicViewViewController *initialViewController = [self viewControllerAtIndex:0];

    [initialViewController setImageViewToDisplay];

    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];

      

+3


source to share


1 answer


Probably your problem is that you first added the button as a subview and then created a page controller and added it as a "on top". Subviews added first are always placed in subviews that are added later by default.



If you move your button creation code after the page code in this method, your button should appear on top of the page controller.

+3


source







All Articles