0

I was trying to make one of the nstextfieldcell unselected for a particular condition. I have attached the sample code:

 -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
if(tableView == resizeTV){
    if([[tableColumn identifier] isEqualToString:@"Name"]){
        if([[cell stringValue] isEqualToString:@"Cate"]){
            [cell setSelectable:FALSE];

        }
    }
  }
}

The cell is still being selected on checking the condition. I have binded the tableview to the class name for tabledatasource and datadelegate. I still can select the cell. Am I doing it wrong? Experimented table

DesperateLearner
  • 1,115
  • 3
  • 19
  • 45

1 Answers1

0

Use NSTableView method to unselect cell setSelectionHighlightStyle:

-(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    if(tableView == resizeTV){
        if([[tableColumn identifier] isEqualToString:@"Name"]){
            if([[cell stringValue] isEqualToString:@"Cate"]){
               [table_view setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];

            }
      }
 }

}

Use this delegate method for unselect particular row

- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
{
    if (row==7)
    {
        [table_view setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];

    }
    else
    {
        [table_view setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];

    }
    return YES;

}
NewStack
  • 990
  • 8
  • 19