2013-02-10 27 views

回答

2
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    MyCustomCell *selectedCell = (MyCustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 

    //selectedCell.textLabel.textColor = <#your color#> 
    //selectedCell.myImage = <#your image> 

} 

如果你想改變選中的單元格backgroundColor,試試這個。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *cellId = @"cellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath]; 
    if(!cell) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; 

     UIView *bgColorView = [[UIView alloc] init]; 
     [bgColorView setBackgroundColor:[UIColor redColor]]; 
     [cell setSelectedBackgroundView:bgColorView]; 
    } 
} 
+0

謝謝,我已經做了this.But當我選擇另一小區,則首先選擇單元和第二選擇單元格都具有突出image.I想避免that.I想要的缺省小區選擇行爲(當我選擇第一個單元格後選擇另一個單元格時,第一個單元格圖像應該是正常圖像,第二個單元格圖像應該是高亮顯示的圖像)我該怎麼做到這一點? – harshiYL 2013-02-10 16:27:34

+0

我得到它通過使用完成 - (無效)的tableView:(UITableView的*)的tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {//selectedCell.textLabel.textColor = <#your顏色#> //selectedCell.myImage = <#your image> }然後,我可以取消單元格取消後的正常圖像 – harshiYL 2013-02-10 17:34:09

相關問題