UIPageViewController中的按钮

时间:2014-09-02 20:58:26

标签: ios uipageviewcontroller

我想将UIButton添加到我的UIViewController中。我在所有屏幕上都有一个UIPageViewController。当我尝试添加此按钮时...屏幕上没有可见的按钮。我做错了什么?

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

1 个答案:

答案 0 :(得分:3)

您的问题很可能是您将该按钮添加为首先的子视图,然后创建了页面控制器并将其视图“添加到”按钮之上。首先添加的子视图始终默认位于 子视图下,稍后添加。

如果您将按钮创建代码移动到该方法中的页面控制器代码之后,则您的按钮应显示在页面控制器的顶部。