Displaying Core Data using Cocoa binding programmatically
Displaying Core Data using Cocoa binding programmatically
- Subject: Displaying Core Data using Cocoa binding programmatically
- From: "Bill So" <email@hidden>
- Date: Fri, 12 May 2006 18:50:22 +0800
Dear all,
I've got a problem about creating and displaying stuff using Core Data
and Cocoa Binding.
The situation is pretty simple:
- Created a core data cocoa application project (not nspersistentdocument type)
- Created a custom controller and make it the delegate object of the
application.
- implemented the "awakeFromNib" method in the custom controller
the awakeFromNib function will programmatically create some
NSManagedObject. The code is as follow:
myObj = [NSEntityDescription
insertNewObjectForEntityForName:@"Account"
inManagedObjectContext:[appDelegateObj managedObjectContext]];
[myObj setValue:@"testing" forKey:@"id"];
[myObj setValue:@"peter" forKey:@"first_name"];
[myObj setValue:@"jackson" forKey:@"last_name"];
[[self managedObjectContext] save:&error];
However, the data is not displayed in the GUI. I m using
NSArrayController and bind it to a NSTableView. The array
controllers' managedObjectContext is bound to the application delegate
and "automatically prepare content" is checked.
According to Core Data documentation (
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdBindings.html
), the runtime should read data from CoreData stack after running
awakeFromNib and windowControllerDidLoadNib:
If I didn't interpret the doc wrongly, the Cocoa Binding should fetch
data from Core Data after awakeFromNib is called.
Do I have to use addObject in NSArrayController instead of using
insertNewObjectForEntity?
Should I call any function to notify NSArrayController to fetch the
content again??
Please kindly advise.
Thanks for your help!
Bill
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden