【发布时间】:2013-11-07 12:37:34
【问题描述】:
我有一个名为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 类中看到按钮。
我在哪里做错了?请帮助并提前致谢。
【问题讨论】:
-
您尝试为按钮添加标题或至少添加背景颜色?
-
哦,是的,真的,伙计,我忘了在添加背景颜色后检查它是否有效。
-
方法名称不要以大写字母开头,也不要使用 On 前缀。 iOS 不是 DotNet。
标签: ios iphone ipad class uibutton