2013-04-08 20 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