【发布时间】:2020-08-05 13:04:36
【问题描述】:
我在 UITableViewCell 中有多个按钮。只有最后一个按钮是可点击的。我在customCell.h 文件中定义了我的按钮
以下是我的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell;
if (IS_IPAD) {
cell = [tableView dequeueReusableCellWithIdentifier:@"VCustomCell_iPad"];
}else{
cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell_iPhone"];
}
NSDictionary *dicCustom = [self.arrCustom objectAtIndex:indexPath.row];
[cell configureVanStockDetail:dicCustom];
[cell.btnOrder addTarget:self action:@selector(btnPurchaseOrderClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
以下代码来自customCell.h文件
@property (strong, nonatomic) UIButton *btnOrder;
来自CustomCell.m 文件的代码
- (void) configureVanStockDetail:(NSDictionary *)objCustom {
...
...
int count = 0
for (NSDictionary *dicPO in arrPO) {
self.btnOrder = [UIButton buttonWithType:UIButtonTypeCustom];
self.btnOrder.translatesAutoresizingMaskIntoConstraints = NO;
self.btnOrder.tag = count;
[self.contentView addSubview:self.btnOrder];
count++;
}
}
从上面的代码中,谁能告诉我为什么只有最后创建的按钮是可点击的。
【问题讨论】:
-
我创建了一个新项目并使用自定义 tableview 单元格制作了一个表格视图,并且选择器按钮被添加到所有单元格 github.com/CongL3/StackOverFlowQuestions 这让我相信它在代码之外的东西正在向我们展示
-
@CoNgL3 感谢您的努力。在这里,我在运行时以编程方式创建按钮。
标签: ios objective-c uitableview uibutton