Re: Programmatically get treecontroller selection
Re: Programmatically get treecontroller selection
- Subject: Re: Programmatically get treecontroller selection
- From: Steven Hamilton <email@hidden>
- Date: Tue, 20 May 2008 20:10:58 +1000
On 20/05/2008, at 5:18 AM, Jonathan Dann wrote:
On 19 May 2008, at 13:29, Steven Hamilton wrote:
I have a core data master-detail interface that consists of a
sourcelist on the left and a tableview.
The source list displays object from a core data entity. THe table
view will be populated by a custom datasource as I have to do some
data munging on the way from core data to the tableview. My custom
controller (datasource) is based on NSObject and has the standard
tableview delegate methods.
The tableview is also populated based on the selected item in the
source list. So I've setup a notification from the outlineview to
call a method in my custom controller. This works fine and when I
execute it I'm trying to get the outlineview's treecontrollers
selection like so;
NSString *accountName = @"default"; //set initial string value
NSLog(accountName); // check logging
object = [MLoutlineViewController selection]; //get selection
object from treecontroller (proxy of core data entity)
accountName = [object valueForKey:@"name"]; //get name property
from object
The object being returned from the selection is always NULL.
Console shows the following;
2008-05-19 22:25:46.990 moolahcoredata[664:10b] Cannot perform
operation without a managed object context
2008-05-19 22:25:46.996 moolahcoredata[664:10b] default
Now, I know the context error is probably because the outlineview
starts up with an item selected, probably before core data is
initialised properly. I've also read that every controller has to
have the context bound. My controller is based on NSObject, it
doesn't have bindings and I'd rather do things programmatically
just now. Do I need to somehow use the context to get the
selection? If so, how? I know context is needed for adding,
fetching etc but to get an object from a treecontroller? I don't
think so somehow.
A few things here make me think that you haven't got the idea of
using NSControllers at all. If you've coded up an NSOutlineView
datasource then the tree controller has nothing to do with your
setup. Without bindings how have you linked the tree controller to
the outline view? The way its traditionally (and designed to be)
used is that the tree controller is the outline view's data source.
The tree controller is then bound to the managed object context.
There are many tutorials online about how to set this up with and
without Core Data. Can you clarify your setup please.
It's explained in the first paragraph but I do tend to ramble a bit so
I'll reword it better.
I have an NSOutlineVIew bound to a NSTreeController in entity mode
bound to an entity called "Account" which has a NSString called "name"
I also have a NStableview which isn't using bindings but is using the
normal delegate/datasource method. The datasource (which I called
controller above) receives a notification from the outlineview that
the selection has changed. In this datasource method called by the
notification I want to get the "name" attribute of selection in the
outlineview. I've attempted to do that by using the "selection" method
of the NSTreeController. However, the object I'm getting back is null.
The selection method should return back a KVC compliant proxy object
from which I should be able to get the name.
For reference, my datasource is an NSObject, It doesn't support
bindings nor do I want it to. This datasource does everything
programmatically.
_______________________________________________
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