Ios 按钮在添加背景时被禁用

Ios 按钮在添加背景时被禁用,ios,uiview,uiviewcontroller,Ios,Uiview,Uiviewcontroller,我正在使用Parse anypic教程,我想创建一个不同的UI。但是我有一些麻烦 因此,我的ViewController是: @interface PAPHomeViewController () @property (nonatomic, strong) PAPSettingsActionSheetDelegate *settingsActionSheetDelegate; @property (nonatomic, strong) UIView *blankTimelineView; @en

我正在使用Parse anypic教程,我想创建一个不同的UI。但是我有一些麻烦

因此,我的ViewController是:

@interface PAPHomeViewController ()
@property (nonatomic, strong) PAPSettingsActionSheetDelegate *settingsActionSheetDelegate;
@property (nonatomic, strong) UIView *blankTimelineView;
@end

@implementation PAPHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"LoadView is called");

    // Present Anypic UI
    [self presentUI];

}

-(void) presentUI {

/*UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        [backgroundImageView setImage:[UIImage imageNamed:@"DefaultAnypic.png"]];
        self.view = backgroundImageView;*/

    // Settings button
    self.settingsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.settingsButton addTarget:self
               action:@selector(settingsButtonAction:)
     forControlEvents:UIControlEventTouchUpInside];
    [self.settingsButton setTitle:@"Settings" forState:UIControlStateNormal];
    self.settingsButton.frame = CGRectMake(200.0, 200.0, 100.0, 100.0);
    [self.view addSubview:self.settingsButton];
}
@interface PAPHomeViewController : PAPPhotoTimelineViewController

@end
其.h文件如下所示:

@interface PAPHomeViewController ()
@property (nonatomic, strong) PAPSettingsActionSheetDelegate *settingsActionSheetDelegate;
@property (nonatomic, strong) UIView *blankTimelineView;
@end

@implementation PAPHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"LoadView is called");

    // Present Anypic UI
    [self presentUI];

}

-(void) presentUI {

/*UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        [backgroundImageView setImage:[UIImage imageNamed:@"DefaultAnypic.png"]];
        self.view = backgroundImageView;*/

    // Settings button
    self.settingsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.settingsButton addTarget:self
               action:@selector(settingsButtonAction:)
     forControlEvents:UIControlEventTouchUpInside];
    [self.settingsButton setTitle:@"Settings" forState:UIControlStateNormal];
    self.settingsButton.frame = CGRectMake(200.0, 200.0, 100.0, 100.0);
    [self.view addSubview:self.settingsButton];
}
@interface PAPHomeViewController : PAPPhotoTimelineViewController

@end
PAPPhotoTimelineViewController也是一个独立的ViewController,Home从中扩展而来,它是一个tableViewController,也称为ViewDidLoad

问题:

通过上面的代码,我看到了我的按钮,我可以点击我的按钮

但是,如果我取消对背景的注释,我确实看到了背景,我确实看到了按钮,但是它不能被点击——这就像没有对按钮的触摸被识别一样


我也很困惑,现在我正在扩展另一个同样实现viewDidLoad的ViewController,为什么它们都被调用,按照什么顺序等等。

您不应该将新的
UIView
分配给您的
self.view

而不是
self.view=backgroundImageView,只需像随机视图一样添加它

[self.view addSubview:backgroundImageView];

这样做,您将按照正确的方式添加子视图:您的
backgroundImageView
将显示在您的视图中,您的按钮将添加到它上面。

您保存了我的一天!将在几分钟内接受它将成为合格的。