controlTextDidEndEditing for View Based NSTableView

I have an older MacOS app that uses cell based tableviews. I am in the process of converting them to view based but hit a snag. When a cell based table ends editing the table view is sent as the object of the notification but when a view based table its the text field.

My code currently checks which table view is sending the notification and updates needed objects. If I switch to view based tables it looks like I'll have to assign tags to each cell view in order to identify it. Is there any way to get the table view for the textfield that ended editing?

Here's what my current code looks like...

-(void)controlTextDidEndEditing:(NSNotification *)aNotification    
    {
    NSControl *theControl = [aNotification object];    

    if (theControl == [self myColorTableView])
        {
        [[[[self myColorArrayController] selectedObjects] objectAtIndex:0] updateMe];
        }
     }
Accepted Answer

Yes, I usually set tags:

    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {

  // … code
                cellView.textField!.tag = row + 256 * column. // If less than 256 rows ; otherwise         cellView.textField!.tag = row + 256 * column

This is a multiplexed value of row and col.

I attach an IBAction to the tableViewCell:

    @IBAction func cellContentDidChange(_ sender: NSTextField) {
        
// Let's find row and coll by demuxing the tag
        let rowIndiv = highWordTag % 256
        let colVar = (sender.tag - rowIndiv) / 256

(that's Swift, but easily adaptable to objC)

Claude, thanks for confirming my suspicions. I like how you assigned tag values in tableViewForColumn, I hadn't thought of that. I think I will use that but assign the same value for all cell views in a given table since my bindings don't need row and col info to do their job. I like your use of multiplexing, which is new to me. Would you mind clarifying a few things?

  1. When setting the mux value what is column.? Is the trailing dot a typo? The comment after that line seems to suggest a conditional but I don't see it in your code.
  2. When demuxing what is highWordTag?

Thanks for the help!

controlTextDidEndEditing for View Based NSTableView
 
 
Q