Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法在视图上添加UIButton_Ios_Iphone_Ipad_Class_Uibutton - Fatal编程技术网

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];

}