2013-04-08 19 views
2

如何使单元格透明。我只想显示有选选中的单元格,我这样做:如何为UITableView中的选定单元格创建透明背景

- (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点击添加和删除复选框。也许这不是正确的做法吗?

回答

1

你可以阅读在这里做透明UITableViewCell S: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; 
} 
+0

透明的后台代码很好,但你给我看的第二部分就是我所需要的 – Pittfall 2013-04-10 18:01:13