gpt4 book ai didi

ios - UITableView 无法在 iOS 中显示正确的按钮颜色

转载 作者:行者123 更新时间:2023-11-28 20:12:00 25 4
gpt4 key购买 nike

我使用了BVReorderTableView https://github.com/bvogelzang/BVReorderTableView重新排序 TableView 中的行。但是我有一个问题:当我将 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;
}

此外,我只想隐藏第一行的按钮,其他行仍然显示。我怎样才能做到这一点?谢谢

最佳答案

隐藏第一行的按钮:

    if (indexPath.row == 1){
prioritybtn.hidden = YES;
prioritybtn.userInteractionEnabled = NO;
} else {
prioritybtn.hidden = NO;
prioritybtn.userInteractionEnabled = YES;
}

return cell; 之前添加这个

关于颜色,在初始化按钮的地方添加:

 UIButton *prioritybtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
prioritybtn.backgroundColor = [UIColor greenColor]; //put the color you want

关于ios - UITableView 无法在 iOS 中显示正确的按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19901865/

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