1

I have clean OS X Storyboards project, Using an Array Controller I bonded Core Data and a NSTableView. It is showing the data. I can add/edit data. But when I click comm+Q, Core Bindings is not saving. Why?

enter image description here

As you can see, I added a special '911 Save' button to call AppDelegate.saveAction which is inside the View Controller. Why? I don't know. I had to create one because the blank project did not have one. Your solution will help me get rid of this button :)

Also, Core Bindings is not deleting the row I selected.
On top of that, each run shows a different order for 'Name'. How do I sort this?

please help!


Can't show you my code because I did not add any code yet :) There should be a way to add video to StackOverflow. Clean set up with NO CODE enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

Diversity
  • 209
  • 1
  • 3

2 Answers2

0

Your issue is essentially a duplicate of the one answered here, albeit with storyboards.

When you add that "app delegate" object to the VC, you're not creating a pointer to [NSApp delegate], you're creating an entirely new instance of the AppDelegate class that gets initialized when the view loads, but it certainly never gets attached to the NSApplication as a delegate. There is nothing in your AppDelegate class that guarantees it's a singleton attached the the application, so the storyboard has helpfully created another AppDelegate instance for you, and it even has a MOC property to bind to. It's just not the app delegate, so it (probably, depending on the XCode boilerplate stack) never initializes that MOC.

The simple workaround is to just bind through the application with a keypath beginning with delegate.

Community
  • 1
  • 1
stevesliva
  • 5,351
  • 1
  • 16
  • 39
0

Rather than creating a new instance of App Delegate in the Storyboard, I found a solution by creating a reference to [AppDelegate managedObjectContext] by adding the @property in the ViewController.h and directing to App Delegate in the implementation file.

//ViewController.h
@interface ViewController : NSViewController
@property (weak, nonatomic) NSManagedObjectContext *managedObjectContext;
@end

//ViewController.m
- (NSManagedObjectContext *)managedObjectContext {
    return [(AppDelegate *)[[NSApplication sharedApplication] delegate] managedObjectContext];
}

On the Storyboard, I then set the Array Controller to bind to View Controller, and the Model Key Path to managedObjectContext (the property on the ViewController class).

After doing this, the data I entered was persisting.

Andy Shephard
  • 1,726
  • 17
  • 26