controlTextDidEndEditing only tells me the tableView


#1

Of the messages from the NSTableView that are send to the AppController as a delegate, none seem to be appropriate except one that’s from NSControl. If I have a controlTextDidEndEditing method in my AppController, it gets notified when I edit a line in the table view. I looked up the parameter it sends along, NSNotification, and it has an instance variable “object”. Kinda good, I can see what object sent the notification.

  - (void)controlTextDidEndEditing:(NSNotification *)notification {
	NSLog(@"controlTextDidEndEditing: = %@", [notification object]);   }

Well, I really want to know the line in that table view that was being edited. So I did this to see what line was being edited:

 - (void)controlTextDidChange:(NSNotification *)notification   {
	 editedRow = [[notification object] selectedRow];
	 NSLog(@"selected row is %d", editedRow);
	NSLog(@"control Text Did Change = %@", [notification object]);     }

This still doesn’t help me, though. I want to know what cell was edited, and what string was put in it.
I’m only able to know what table view (and I only have one) was touched.
Any tips?


#2

I can see in the debugger that my (self)->taskList (the NSTableView) has an item/variable in it called _editingCell.
This _editingCell seems to have what I need inside it, the _contents, a NSCFString that has the value of the cell I just got done editing.

There doesn’t seem to be a method [taskList editingCell], though. I can’t see into the NSTableView to pick out that changed text.

I’m getting somewhere, though. Not sure if I’m getting closer, or like a lost person in the woods during a snow storm, I’ll walk for an hour or so and find I’m still in the same place.


#3

OK, there were more things in the NSNotification that I just learned about.

[[[notification userInfo] valueForKey:@“NSFieldEditor”] string]

Yep, I had to go one up the object tree from NSTableView to NSControl, and look at it’s delegate methods. I have been using NSControl’s delegate method all along, controlTextDidEndEditing. I read the documentation’s terse explaination, and see that it’s userInfo dictionary has something in it called @“NSFieldEditor”.

Well, I used xcode’s debugger gdb to look into the objects at a break point, and saw po [notification userInfo] does indeed have a NSFieldEditor in it, and that has a NSTextView inside. After reading ahead, I knew that those “valueForKey:” things might be the ticket here.

The only thing I think I’m still doing the hard way is getting the index to the data array. I’m getting it during editing by using the delegate controlTextDidChange, and setting an instance variable int editedRow during the editing operation. This sends lots of messages, one for every keystroke, so it’s chatty. But I do get, from [[notification object] selectedRow], an int of what row is being edited. Then, when it’s done being edited, I have that instance variable to use to tell me what row to replace in my data array.

There has to be an easier/simpler way, but as I look at the userInfo record, I see screen coordinates of the cell, but no index of the surrounding NSTableView.

Mr. Hillegass is making me read and try to understand the documentation.


#4

So, I can implement any of the methods in the “NSTableViewDelegate Protocol Reference” that I want?
Like tableView:shouldEditTableColumn:row: ?

Cool. That’s a one-shot way to get the row number and store it.


#5

It still seems like I should be able to get the Table View row that was just done being edited somehow, but I’m gonna get my 10 hours of sleep now.

If anyone knows how to do that, please do tell. Go Spain, or Netherlands (my wife is Peruvian).


#6

Wow, did I blow it. Right in the book, there’s mention of another delegate method, tableView:setObjectValue:forTableColumn:row:

I looked at that paragraph, and thought to myself “self, maybe that’s the one-shot solution”.

So I typed it in, and it still didn’t work.

So I commented out all the goofy delegate methods I was using, thinking somehow they were interfering with this one. Voila, it works.

How does one tell if a method/message is getting blocked? My guess is, one of the methods I was implementing was the root of this message. When I grabbed the message, it stopped along some message chain. There’s gotta be a way to get a message, then continue to send it along, right? I’ll probably read about it in a few days.

I’m so glad Cocoa isn’t as messed up as I am.