• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSObjectController and Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSObjectController and Core Data


  • Subject: NSObjectController and Core Data
  • From: Kevin <email@hidden>
  • Date: Tue, 13 Feb 2007 14:23:35 -0600

I'm having a couple of different problems with NSObjectControllers and NSTextViews in my Core Data application.

Here's my setup: I have a custom NSView which displays a variable number of NSTextViews that are created dynamically. Each of these text views is bound to an NSObjectController. Each NSObjectController is bound to a distinct NSManagedObject. The custom view is driven using the row that is currently selected in an NSTableView (backed by an NSArrayController).

I'm using an InMemoryStore with two main Entities: Item and Attribute. Item has a to-many relationship with Attribute. Items are managed by the NSArrayController and Attributes are managed by individual NSObjectControllers.

Problem #1:
When I select a row in the table view, the text doesn't show up right away in the text views. So, if I have 3 text views in my custom view, I can see them slowly being populated when I select a row.


Problem #2:
When I edit the contents in any of the text views and then decide to save my managed object context WITHOUT leaving the text view, the changes are not recorded. If I leave the text view, the changes do get recorded.


Here's the code in my custom view where I create the NSObjectControllers and NSTextViews:

// Get attribute
NSManagedObject *attribute = ...

// Create controller
NSObjectController *controller = [[[NSObjectController alloc] initWithContent:nil] autorelease];
[controller bind:@"managedObjectContext" toObject:[NSApp delegate] withKeyPath:@"managedObjectContext" options:nil];
[controller setFetchPredicate:[NSPredicate predicateWithFormat:@"self == %@", attribute]];
[controller setEntityName:@"Attribute"];


[controller fetch:self];

[objectControllers addObject:controller];

// Create text view and bind to controller
NSTextView *textView = [[[NSTextView alloc] initWithFrame:NSMakeRect (10, y, 100, 20)] autorelease];
[textView setRichText:NO];
[textView bind:@"value" toObject:controller withKeyPath:@"selection.text" options:nil];


[self addSubview:textView];

- Kevin
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: NSObjectController and Core Data
      • From: "Sean McBride" <email@hidden>
  • Prev by Date: Re: How to set scheduling in NSThread based application
  • Next by Date: Core Data "Integer 32" attribute type <-> NSNumber
  • Previous by thread: Re: NSTask: Arguments with Ticks
  • Next by thread: Re: NSObjectController and Core Data
  • Index(es):
    • Date
    • Thread