gpt4 book ai didi

objective-c - 添加为 UIView 的 subview 后按钮不可单击

转载 作者:可可西里 更新时间:2023-11-01 06:23:48 25 4
gpt4 key购买 nike

我创建了一个名为 UICustomButton 的类,它是 UIView 的子类。我将 UIButton 作为 subview 添加到 UIView 中,如下面的代码所示:

-(id)initWithButtonType:(NSString *)type
{
self = [super init];
if (self)
{
self.customButton = [self setupButtonWithTitle:type andFrame:frame];
[self addSubview:self.customButton];
self.customButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

}
return self;
}

我面临的问题是,虽然出现了按钮,但它们是不可点击的。我将按钮添加到 UIView 的方式有问题吗?

enter image description here

编辑:要补充一点,我将这个自定义按钮类实例用于单元格:

UICustomButton *customButton = [[UICustomButton alloc]initWithFrame:someFrame];
[cell.contentView addSubView:customButton];

最佳答案

检查您的 UICustomButton 对象的框架,以及 self.customButton 是否在其 superView 之外。

关于objective-c - 添加为 UIView 的 subview 后按钮不可单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7896969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com