简体   繁体   English

无法在自定义UIView上单击UIButton

[英]cannot click UIButton on custom UIView

I have a custom view, for example ParentView : UIView . 我有一个自定义视图,例如ParentViewUIView Inside this view I have one UIButton that I'm adding programatically as 在此视图中,我有一个UIButton ,我以编程方式添加为

UIButton *btn = [[UIButton alloc] initWithFrame:frame];
        [btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpOutside];
    [self addSubview:btn];

and the action: 和动作:

-(void)buttonPressed:(id)sender{
    NSLog(@"button pressed: %@",sender);
}

In my storyboard I have a basic View, whose class I've set to ParentView. 在我的情节提要中,我有一个基本的View,我将其类设置为ParentView。 The initialization is indeed called, and the UIButton is created fine, just the action is not called. 确实调用了初始化,并且UIButton创建良好,只是未调用操作。 The ParentView has userInterActionEnabled checked. ParentView已选中userInterActionEnabled

使用UIControlEventTouchUpInside事件代替UIControlEventTouchUpOutside事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM