2013-02-10 59 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

相关问题