2010-10-10 43 views
0

我有一个UITableView,我想用它来允许多选。我将大部分功能汇集在一起​​,但遇到一个小问题。UITableView多选

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"Selected"); 
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 

    if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) { 
     [selectedCell setBackgroundColor:[UIColor grayColor]]; 
     [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark]; 
     [[selectedCell textLabel] setTextColor:[UIColor whiteColor]]; 
    } else { 
     [selectedCell setAccessoryType:UITableViewCellAccessoryNone]; 
     [selectedCell setBackgroundColor:[UIColor clearColor]]; 
     [[selectedCell textLabel] setTextColor:[UIColor blackColor]]; 
    } 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

这是我使用,以保持选定单元格中的代码,但是当用户点击该单元格,在aaccessory视图变成白色,然后变成回蓝。

对于我来说,让配件视图保持白色的最佳方式是什么?

感谢

回答

2

我相信简单的方法来实现这一目标是通过创建具有对号形象自定义的ImageView(你需要把它作为白色勾号),选择时设置为附属视图。

这将避免accessoryview的标准行为并实现您的目标。