Retrieve information from NSTableView

If you have a NSTableView with many rows (1 column), what would the language look like to retrieve the content of a user-selected row? I have been looking through all sorts of documentation and I don’t seem to be able to convert what I’m seeing in Obj-C to ASOC. (Maybe what I’m seeing isn’t doing what I think it’s doing anyway…I don’t know Obj-C that well)

Also, is there a way for a user to select different records in the table (like ctrl+click or opt+click), or is that something I need to add to my code too?

Any help would be appreciated!

Thanks
Chrissy

Chrissy,

Using Objective C :

NSTableView *tableView;

rowIndex = [tableView selectedRow];

I am not quite sure how you would this in AppleScript, sorry…

Best Regards,

Bill Hernandez
Plano, Texas

Im not 100% sure but i think it might be

property Class NSTableView tableView:missing value  --Could be wrong you should double check this syntax
property rowIndex:missing value

set my rowIndex to tableView's selectedRow()

I believe the correct syntax would be:

property tableView : missing value – this should be bound to the object with Interface Builder

set rowindex to tableView’s selectedRow() as integer

Thanks for the help! That got me closer, but I don’t want it to return the index, just the content. I’ve thought about using the index number to locate the content from my list, but if the user sorts the table, the list is now no longer in the same order as the content. (I tried the “sorting is overrated” excuse, but it didn’t fly…haha)

I’ve learned a lot from this post, seeing the way something is written in Obj C vs. ASOC really helped. I think I’m getting closer to having a tiny grasp on this stuff, but I’ve run into something else. How would you AppleScriptObjC-ize this statement:

-(void)setAllowsMultipleSelection:(BOOL) flag —the flag being YES or NO (I want Yes)

I’ve tried putting it just like that into my awakeFromNib handler but it didn’t even compile…

That’s where an NSArrayController is so useful – if you use one, you can ask it for the selectedObjects, and you can also ask it for the items in sort order via arrangedObjects.

myTable’s setAllowsMultipleSelection_(true)

But why bother when you can do it in Interface Builder? In the Inspector under Attributes look for Selection/ Multiple.

Thanks for the advice!

I’m utterly stumped right now. I’ve been trying for a few days now to get the array controller working with no luck. What should be connected to what, and what should be bound to what? I’ve managed to go from having a close-to-finished project to one that won’t even launch the window! :mad:

Here’s what I have:

Property- singleVersions - this is the identifier for the column in the table

App Delegate - I have a ref. Binding from singleVersions to the content array array controller. I also have a referencing outlet from my dataSource to Table View

Array Controller - I have a binding from Content Array to Impo Combine App Delegate singleVersions. I also have a ref. Binding from arrangedObjects.singleVersions to Value Table Column (singleVersions)

Table Column - in the bindings section I have a binding from value to array controller arrangedObjects.singleVersions, and the selector field is set to “compare:”

if I take the arrangedObjects.singleVersions referencing binding off, the program will at least compile and launch, but it has yet to work properly.

I’m very sorry if you already covered this in your tutorials, Craig. I’m trying to keep up with you!

Chrissy,

You should use either a datasource or an NSArrayController and bindings – mixing the two is difficult to do.

I don’t know if it is any help but here is my twoTableWithBindings example from a few months back. Shane and Craig helped me work out the bindings and array controller stuff. Array Controllers are the way to go. Forget the dataSource unless absolutely necessary. Also you get the sorted state of the table with arrayController’s arranged objects() which is a life saver.

I’ll post the project here. I also added drag and drop (via Shane’s example) for the big table to help out someone else this week. And for good measure I added writeToFile_atomically_ to save the data (except for a workaround for the images.)

It shows how to connect two tables with bindings and bind the table’s content to the array controller. It may be a bit confusing with two tables involved but it’s all there.

http://rdutoit.home.comcast.net/~rdutoit/pub/two_bound_tables_sample.zip

cheers, Rob

Well my programming project got put on the back burner, but thank you Rob for posting your project!! When I get through with my new project I’ll use yours, and I’m sure that it is just what I needed. Thank you so much for all your help.