views:

56

answers:

1

Hello, I'm am a beginner in mac os x development and am trying to get started with all this.

Here is my problem : I've create a non-document based cocoa app using core data as storage. I've added an entity and attributes to the xdatamodel. In IB i've created an NSArrayController and linked it properly. I've created an nstableview binded to the nsarraycontroller. Next I added a button linked to nsarraycontroller with the " add: " method.

When I try it out, I can add and edit the items in the table.

Here comes the problem: Core data is supposed to save everything automatically, but to make sure i linked the "save" button in the menu to the appdelegate and to the " file's owner" , first responder, application... everything possible ( with both " save :" and " saveaction:" methods ).

And still it doesn't save when clicking save: when I restart the cell created ( and renamed ) are gone.

And also, I didn't even edit the source code yet; core data for such simple tasks is supposed to only need Interface builder.

Please help me for this, I haven't found any threads resolving this problem.

Thank you in advance.

A: 

To save the changes, you'll have to call save: on the managed object context.

If you look at the CoreDataBooks example, you'll see how they call it like this as a result of the user pressing save:

- (IBAction)saveAction:(id)sender {

    NSError *error;
    if (![[self managedObjectContext] save:&error]) {
        // Update to handle the error appropriately.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        exit(-1);  // Fail
    }
}
Ken Aspeslagh
I don't get it, should I create a "managedobjectcontext" object in IB ? Because the save menu item is linked to everything possible with "save:" function. It still doesn't work.thanks,
Paul Rostorp
The menu should call an action like the one I posted in your app's controller. Look at the sample code.
Ken Aspeslagh