1
votes

I am new to Objective-C and Cocoa programming (coming from a background of C/C++ development years ago on other platforms). I am writing an application to download remote data on a recurring basis (i.e. every X number of seconds), parse through it, sort/filter it into an NSArray, and display/update said data in an NSTableView. After reading a few books, a lot of Apple OS X Reference material, and experimenting I have managed to implement everything (the remote data download, parse/filter logic, in-memory storage, etc.) except actually updating the NSTableView with the data.

I am not sure if I am just missing something obvious or just how my application should be laid out following the MVC concept, or if Interface Builder's lack of actual code generation is just not what I am used to, but I cannot seem to determine how I can programmatically access/manipulate the NSTableView that was created in Interface Builder.

I tried (in Interface Builder) dragging a NSObject instance of my NSArray-based object in, where-then I can connect my NSTableView's Outlet/datasource, but this results in an another instance of my NSArray-based object (not connecting the NSTableView to my existing, programmatically-declared and instantiated object). Likewise, I thought to set my NSTableView's datasource programmatically, but I have not been able to determine how I can programmatically refer to the NSTableView object stored in the .xib/.nib file other than via a Tag (for which I have not been able to determine what object to call the viewWithTag: method from, after setting my NSTableView's Tag value in Interface Builder).

Any suggestions, advice, or guidance would be greatly appreciated. This feels like one of those things that will be very simple (and once I have it working in front of me, it will make a lot more sense), but I just cannot seem to get a starting point/example working.

1
Do you have an IBOutlet NSTableView in your class's header file?BoltClock♦
I would recommend that you purchase one of the beginner iPhone dev books as it covers the typical process in these items - create the header, assign IBOutlets, run IB, attach GUI to IBOutlets, etc.KevinDTimm
... or at least read the introductory documentation Apple provides free of charge, linked right from the developer.apple.com page ...Joshua Nozzi
I worked through multiple examples of using Interface Builder, but all revolved around Actions from one control triggering updates to others (where data was always stored in objects all setup in Interface Builder). In my case, I have data already (without any user input) in a programmatically-instantiated object. I can display it out via NSLog, etc. but I do not understand how to "connect" that to the GUI to display it. I know it must be something simple that I am just not catching or grasping. I appreciate any and everyone's time spent answering.DAz

1 Answers

2
votes

You need to attach an instance variable in your table's controller class to the table in interface builder. Declare a table in your class like this:

IBOutlet NSTableView* myTable;

...

@property (nonatomic, retain) IBOutlet NSTableView* myTable;

And be sure to synthesize it.

In the connections tab of the info window in interface builder, connect your controller's new outlet to your table. Then when your view is loaded from the XIB, this outlet will be connected.

Hope that helps some.