Graphing data from NSArrayController
Graphing data from NSArrayController
- Subject: Graphing data from NSArrayController
- From: Michigan's Captain <email@hidden>
- Date: Sat, 9 Feb 2008 10:14:39 -0500
I'm new to cocoa programming, and I have what I think is a really
basic question. I've searched and searched, but I just can't seem to
find an answer... or I just keep overlooking the answer. Either way,
I'm stuck.
The basic premise is that I want to graph data from an NSTableView.
Here's what I have in place so far.
On the left side of my window, I have an NSScrollView (where the
NSTableView sits). I set this up in a similar manner as I had found
from Apple's site here: [http://developer.apple.com/cocoa/coredatatutorial/index.html
]. I modified it slightly, but basically my NSScrollView has a [+]
and [-] button. Pressing either of these adds/subtracts a row of
data. The data is stored in an NSArrayController (just like the
tutorial in the link above). This side of my window works fine... I
can add data, remove data, edit data. I can save the data and re-open
it later and everything is happy.
On the right side of my window, I am using a custom class derived from
NSView. The class for this view is using Quartz2D calls. I used the
example project from the [/Developer/Examples/Quartz/TLayer/]. I
have made some modifications and by using the CGPathAddLineToPoint,
CGContextAddPath, CGContextStrokePath, Quartz2D methods, I have a
graph that looks quite nice on the screen. But in the
CGPathAddLineToPoint method I just have hard-coded a bunch of random
data.
I guess what I'm just not figuring out is how to get the data from my
NSArrayController (or NSTableView... I don't know which of those to be
using... maybe either works?) to my graphing object. I just want to
update the graph any time that the user adds/edits/deletes the data in
the NSTableView. It seems like it would be so simple, but I'm missing
something.
I was looking into Delegates and the Delegate methods of NSTableView.
I created a separate customized NSObjectController in IB. My plan was
to use the new NSObjectController to get the data from the Table View
and then pass it to the graphing engine where it would then put the
proper points in the CGPathAddLineToPoint method to be graphed. I
tried connecting the content outlet to the new NSObjectController, but
that brings along the ManagedObjectContext too. I didn't know which,
if either, of those that I should use. I added an the following code
to the header of my NSObjectController class...
IBOutlet NSManagedObjectContext *myMOC;
But I couldn't seem to access the data from the TableView.
Sorry if this is too verbose... I just wanted to have enough detail.
Here's the recap...
Recap: I don't know how to set up the code or the IB to pass data
from one object to another. Second, I don't know how to detect the
event that the data in the Table View has changed (thus triggering the
previous sentence).
Thanks for any help!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden