我有一个名为的类名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
课堂上看到按钮。
我在哪里做错了?请帮助并提前致谢。