【问题标题】:cannot click UIButton on custom UIView无法在自定义 UIView 上单击 UIButton
【发布时间】:2014-03-25 18:41:44
【问题描述】:

我有一个自定义视图,例如 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);
}

在我的故事板中,我有一个基本视图,我已将其类设置为 ParentView。确实调用了初始化,并且 UIButton 被创建得很好,只是没有调用动作。 ParentView 已选中 userInterActionEnabled

【问题讨论】:

    标签: ios objective-c uiview uibutton user-interaction


    【解决方案1】:

    使用 UIControlEventTouchUpInside 事件而不是 UIControlEventTouchUpOutside。

    【讨论】:

      猜你喜欢
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 2021-12-29
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多