我的名字叫HomeViewController
,在HomeViewController
里面我正在添加PageViewController
(即APPChildViewController)
这是我的代码:
HomeViewController.h:
@interface HomeViewController : UIViewController<UIPageViewControllerDataSource,UIPageViewControllerDelegate>{
NSUInteger Pageindex;
APPChildViewController *childViewController;
}
@property (strong, nonatomic) UIPageViewController *pageController;
HomeViewController.m:
- (void)viewDidLoad
{
APPChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageController.delegate = self;
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
[self OnLoad]; //Method on APPChildViewController class
}
APPChildViewController:
-(void)OnLoad{
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(20, 20, 130,130);
// [button setTitleEdgeInsets:UIEdgeInsetsMake(20, 30, 00, 15)];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
在我的PageViewController
(即APPChildViewController)中编写此代码后,我无法在APPChildViewController
课程中看到按钮。
我在哪里做错了?请提前帮助和致谢。
答案 0 :(得分:1)
您是否尝试为按钮或至少背景颜色添加标题? :)
答案 1 :(得分:0)
由于OnLoad是APPChildViewController
的一种方法,您应该使用[initialViewController OnLoad]
答案 2 :(得分:0)
你已经调用了HomeViewController的OnLoad方法而不是APPChildViewController - 你需要将方法调用更改为[initialViewController OnLoad]