我使用BVReorderTableView https://github.com/bvogelzang/BVReorderTableView重新排序表视图中的行。但是我有一个问题:当我将 UIButton 添加到每一行时,这个按钮总是显示清晰的颜色。一旦选择了行,这个按钮就会显示出来。
我试过这段代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell;
cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIButton *prioritybtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[prioritybtn setFrame:CGRectMake(220, 0, 70, 32)];
[prioritybtn setTag:4000];
[cell.contentView addSubview:prioritybtn];
}
UIButton *priorityButton = (UIButton*)[cell.contentView viewWithTag:4000];
if ([[items objectAtIndex:indexPath.row] isKindOfClass:[NSString class]] &&
[[items objectAtIndex:indexPath.row] isEqualToString:@"DUMMY"]) {
cell.textLabel.text = @"";
cell.contentView.backgroundColor = [UIColor clearColor];
prioritybtn.hidden= YES;
}
else {
cell.textLabel.text = [items objectAtIndex:indexPath.row];
[priorityButton setSelected:NO];
[priorityButton setTitle:@"Priority" forState:UIControlStateNormal];
priorityButton.enabled = YES;
}
return cell;
}
另外,我只想在第一行隐藏按钮,其他行仍然显示。我怎样才能做到这一点?谢谢