简体   繁体   中英

Cocoa Core data: cannot save Created Items in NSTableview

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.

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]);
        abort();  // Fail
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM