OGeek|极客世界-中国程序员成长平台

标题: ios - 如何为 UITableView 中的选定单元格制作透明背景 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:11
标题: ios - 如何为 UITableView 中的选定单元格制作透明背景

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

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];

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

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

cell.selectionStyle = UITableViewCellSelectionStyleNone;

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



Best Answer-推荐答案


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

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

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}

- (void)tableViewUITableView *)tableView didDeselectRowAtIndexPathNSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
    cell.accessoryType = UITableViewCellAccessoryNone;
}

关于ios - 如何为 UITableView 中的选定单元格制作透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15888799/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4