[英]UIView (subview of ViewControllers view) UIButton cannot receive click events
[英]cannot click UIButton on custom UIView
我有一个自定义视图,例如ParentView
: UIView
。 在此视图中,我有一个UIButton
,我以编程方式添加为
UIButton *btn = [[UIButton alloc] initWithFrame:frame];
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpOutside];
[self addSubview:btn];
和动作:
-(void)buttonPressed:(id)sender{
NSLog(@"button pressed: %@",sender);
}
在我的情节提要中,我有一个基本的View,我将其类设置为ParentView。 确实调用了初始化,并且UIButton创建良好,只是未调用操作。 ParentView已选中userInterActionEnabled
。
使用UIControlEventTouchUpInside事件代替UIControlEventTouchUpOutside事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.