3
我想添加UIButton到我的UIViewController。我在所有屏幕上都有一個UIPageViewController。當我試圖添加此按鈕時......屏幕上沒有按鈕可見。我做錯了什麼?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];
嘗試添加按鈕的最後一個,即在[self.pageController didMoveToParent ...] ..我的猜測是,它由您添加的子視圖覆蓋。 – Mike 2014-09-02 21:45:13
你是對的。它被覆蓋。現在它工作正常。 – DKM 2014-09-02 22:05:42
好吧,我會補充說,作爲一個'官方'的答案,以防萬一以後有人來。 :) – Mike 2014-09-02 22:06:36