For every UITableViewCell I’m creating a UIButton in the tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath method. I want to check if UIButton is already there when creating it, so it’s not added multiple times, but I can’t. Here’s my code:
- (UITableViewCell *)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *cellBottomLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, CELL_HEIGHT, 320.0, 1)];
cellBottomLine.image = [UIImage imageNamed:@"bottomCellImage.png"];
if (cellBottomLine.subviews) {
[cell addSubview:cellBottomLine];
}
copyButton = [BSFunctions createButtonWithNormalImageNamed:@"copyCellButton.png" highlightedImageName:@"copyCellButtonPressed.png" target:self selector:@selector(copyPressedFromCell:)];
[copyButton setFrame:CGRectMake(250, 10, 62, 32.5)];
copyButton.tag = indexPath.row;
if (!copyButton.superview) {
[cell addSubview:copyButton];
}
return cell;
}
1 Answer