• 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
Re: Inserting into NSArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inserting into NSArrayController


  • Subject: Re: Inserting into NSArrayController
  • From: Ron Lue-Sang <email@hidden>
  • Date: Mon, 27 Jun 2005 17:56:42 -0700


Selects inserted objects only applies to objects inserted by add/ insert actions and addObject(s)/insertObject(s) API. When the content changes (like new objects showing up in the context) that doesn't count as an insertion from the controller's standpoint, just a content change.


The former (the IB actions ) are performed delayed, so the addition won't take place until the next run through the event loop.

The array controller listens for notifications from its managedObjectContext for inserted/deleted/updated objects. These notifications are normally sent by the managedObjectContext at the end of a user event, so when your code is done inserting the new managedObject, the controllers haven't heard the notification yet.

What you can do to make the context send the notification earlier is -

    [managedObjectContext processPendingChanges]

Then you can do your [controller setSelectedObjects] invocation.

The reason you get back YES from the setSelectedObjects call is that nothing went horribly wrong. Sure, the controller couldn't find the object you wanted selected, but it's not like commitEditing failed.


I've got an NSArrayController that's bound to a Core Data entity. It is set to "Selects inserted objects", which works fine when I bind a control to the array controller's add: action.

However, if I add an entity using NSEntityDescription's insertNewObjectForEntityName:inManagedContext: it doesn't select the newly inserted object.

I've tried doing it manually, like so:

NSArray *array = [NSArray arrayWithObject:newObject];
BOOL worked = [theController setSelectedObjects:array];

worked comes back as YES, but it doesn't select the newly inserted object. I've checked my bindings and connections in IB and they all look good. Anyone know what might be going on here?

I guess I could use the array controller's add: method and then retrieve a reference to the new object, which will work, but I'd like to know why this isn't working if anyone can help me out.

Thanks,
Jeff


----------------------------- Ronzilla Core Bindings/Cocoa Data


_______________________________________________ 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
  • Prev by Date: Re: pageHeader and pageFooter
  • Next by Date: Re: pageHeader and pageFooter
  • Previous by thread: Re: Inserting into NSArrayController
  • Next by thread: SCNetworkReachability
  • Index(es):
    • Date
    • Thread