2010-10-10 34 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的標準行爲並實現您的目標。