Ios 无法在视图上添加UIButton
我有一个名为Ios 无法在视图上添加UIButton,ios,iphone,ipad,class,uibutton,Ios,Iphone,Ipad,Class,Uibutton,我有一个名为HomeViewController的类名,在HomeViewController内部,我正在添加PageViewController(即APPChildViewController) 这是我的代码: HomeViewController.h: @interface HomeViewController : UIViewController<UIPageViewControllerDataSource,UIPageViewControllerDelegate>{
HomeViewController
的类名,在HomeViewController
内部,我正在添加PageViewController
(即APPChildViewController)
这是我的代码:
HomeViewController.h:
@interface HomeViewController : UIViewController<UIPageViewControllerDataSource,UIPageViewControllerDelegate>{
NSUInteger Pageindex;
APPChildViewController *childViewController;
}
@property (strong, nonatomic) UIPageViewController *pageController;
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
类中看到按钮
我哪里做错了?请提前给予帮助和感谢。由于OnLoad是
APPChildViewController
的一种方法,您应该使用[initialViewController OnLoad]
您试图为按钮添加标题或至少添加背景色?:) 您调用了HomeViewController而不是APPChildViewController的OnLoad方法-您需要将方法调用更改为[initialViewController OnLoad]您试图为按钮添加标题或至少添加背景色?哦,是的,真的,哥们儿,在添加背景色后我忘了检查它是否有效。方法名称不要以大写字母开头,也不要在前缀上使用。iOS不是DotNet。
-(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];
}