UITableViewCell selected row's text color change

后端 未结 4 1023
再見小時候
再見小時候 2021-01-30 12:47

I am having a tableview and I want to know that how can I change the selected row\'s text color, say to Red ? I tried by this code :

- (UITableViewCell *)tableV         


        
4条回答
  •  不要未来只要你来
    2021-01-30 13:04

    I had the same problem, try this!

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        for (id object in cell.superview.subviews) {
            if ([object isKindOfClass:[UITableViewCell class]]) {
                UITableViewCell *cellNotSelected = (UITableViewCell*)object;
                cellNotSelected.textLabel.textColor = [UIColor blackColor];
            }
        }
    
        cell.textLabel.textColor = [UIColor redColor];
    
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    }
    

    That may be the solution to your (and mine) problem.

提交回复
热议问题