【发布时间】:2011-10-25 23:17:13
【问题描述】:
我创建了一个名为UICustomButton 的类,它是UIView 的子类。我将UIButton 添加到UIView 作为subview,如下面的代码所示:
-(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 的方式有问题吗?
编辑:补充一下,我将这个自定义按钮类实例用于单元格:
UICustomButton *customButton = [[UICustomButton alloc]initWithFrame:someFrame];
[cell.contentView addSubView:customButton];
【问题讨论】:
-
setupButtonWithTitle:andFrame:是做什么的?另外,您需要确保如果initWithButtonType:的代码引用self添加选择器buttonPressed,则buttonPressed方法确实在同一个类中实现。
标签: objective-c ios uiview uibutton