【问题标题】:How can I make a transparent background for selected cells in UITableView如何为 UITableView 中的选定单元格制作透明背景
【发布时间】:2013-04-08 20:55:04
【问题描述】:

如何使单元格透明。我只想用我已经完成的复选标记显示选定的单元格:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];

    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    } 
    else {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
}

当我第一次创建单元格时,我会执行下一行代码以消除蓝色背景

cell.selectionStyle = UITableViewCellSelectionStyleNone;

但我有一个奇怪的问题,需要单击 2 次才能添加和删除复选框。也许这不是正确的做法?

【问题讨论】:

    标签: ios objective-c xcode uitableview


    【解决方案1】:

    您可以在此处阅读有关使UITableViewCells 透明化的信息:How to create a UITableViewCell with a transparent background

    至于你的第二个问题,看来这可能是你真正想要的:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    
    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)path {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    

    【讨论】:

    • 我添加的透明背景代码很好,但你给我看的第二部分是我需要的
    猜你喜欢
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2023-03-23
    • 2012-02-17
    • 2011-06-15
    相关资源
    最近更新 更多