0

我有一个名为的类名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课堂上看到按钮。

我在哪里做错了?请帮助并提前致谢。

4

3 回答 3

1

您是否尝试为按钮添加标题或至少添加背景颜色?:)

于 2013-11-07T12:51:05.410 回答
0

由于 OnLoad 是 的一种方法APPChildViewController,您应该使用[initialViewController OnLoad]

于 2013-11-07T12:43:32.513 回答
0

您调用了 HomeViewController 的 OnLoad 方法而不是 APPChildViewController - 您需要将方法调用更改为 [initialViewController OnLoad]

于 2013-11-07T12:55:38.047 回答