views:

174

answers:

2

Hi, I have an NSTableView hooked up to Core Data. Here is what I want to do.

The table has two columns. When I finish editing the first column, and press tab to go to the next column, I want to programmatically populate the second column based on the first column's data. Is there a delegate method that can help me with this?

Thanks

+1  A: 

That's not how a table view works. Every row is one item, and the columns are different properties of that item. Attempting to do otherwise is fighting the framework and the HIG.

Perhaps you want an NSBrowser instead.

Peter Hosey
Huh? Im not sure that makes sense?
Jacob
It does. Every row in a table view displays one item. The questioner is asking to display different lists in each column, which would put multiple, different items in each row (as opposed to properties of a single item). The view to use to display multiple lists in separate columns is an NSBrowser, not an NSTableView.
Peter Hosey
A: 

Yep its not too hard once you understand how the apple frameworks work.

You simply need to have your controller object (that sits behind the table) become a "delegate" to listen for events events in the text field in the first text box.

When your controller receives a message that a user has left the first text box, that data from the first text box can be read and passed onto the model object (which stores all your data).

Your model object would know how to update what should be in the second field and send a message back to your controller that the second column has changed and needs updating

(IF this is confusing you need to read up apples documents on MVC (Model View Controller).)

Jacob
You're assuming there will still be an equal number of items in the second column as the first column. You're also assuming that the “model objects” will somehow represent multiple items, and that each one representing an item for the first column will know which item it should be in the second column. The controller could arrange the last part, but it's still a tremendous hack that fights the framework and the HIG.
Peter Hosey
Peter, I still don't think you understand what I'm trying to do. Imagine a table with two columns. Say I wanted the user to input a number in the first column, and then the second column would populated with the first number multiplied by two. Both columns of each row are related, and will be added as one Core Data Entity.Now, I haven't been able to find a good delegate method that would tell me when the field is switched. But I think I need to know when [tableView selectedCell] changes. I don't know much about how observing works - can you observe a value like that from an IB object?
Alex G