• 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
NSArrayController binding question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSArrayController binding question


  • Subject: NSArrayController binding question
  • From: Arved von Brasch <email@hidden>
  • Date: Sun, 4 Jun 2006 12:25:26 +1000

Hello Cocoa Mailing List,

I have a NSManagedObject subclass (A) which has a to-many relationship with another NSManagedObject subclass (B). Both are controlled by NSArrayControllers.

It used to be the case that I could bind the contentSet of the second NSArrayController (B) to the selection proxy object of the first (A) with the correct keypath for the relationship and everything worked fine. However, the model changed slightly meaning that that the object selected in the first TableView was not necessarily in the NSArrayController (A) that controls the dynamic list. Some of A's objects became permanent and thus I had to remove them from the content of the NSArrayController and then put them back manually using the TableView's DataSource methods. This basically means that the selection proxy object is no longer viable to bind the second NSArrayController's (B) contentSet to, because the selection may be outside of the content of the first NSArrayController.

No problem, I thought. As the first (A) NSArrayController has access to the permanent objects, even if they don't appear in its list, I created a new public key-value compliant method for the real selected object. That is when the selection is changed in the table, the NSArrayController is notified and checks to see what the selection is, setting the real selected object using these methods. This part I am sure works fine. I have tested it extensively in other aspects of the program, and I can guarantee that it correctly points to the real selected object. This, however, does not seem to work as a binding value for the second NSArrayController (B). The second NSArrayController appears to work correctly, in that you can add objects to it, but then they seem to disappear into a void, as run- time errors about the index being out of bounds occur if you try to do anything with these new objects. The new objects will also disappear if the selection in the first tableView (A) is changed and then changed back again.

This is the code from the first NSArrayController subclass (A):

- (void)selectionChanged: (NSNotification *)notification {
// Permanent object is always at top - Additional permeant objects will be added when I get this working.
if ([theTable selectedRow] == 0)
[self setRealSelection: theObject];
else
[self setRealSelection: [[self arrangedObjects] objectAtIndex: [theTable selectedRow] -1]];
}


NSManagedObject *_realSelection = nil;

- (void)setRealSelection: (NSManagedObject *)value {
	_realSelection = value;
}

- (NSManagedObject *)realSelection {
	return _realSelection;
}

The binding for the second NSArrayController (B) is using Controller Key 'realSelection' with the model key path being the same as when selection was the controller key.

I'm clearly doing something wrong, but I can't work out what it is. Can anyone help?

Cheers,

Arved von Brasch
_______________________________________________
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: why doesn't my scrollview scroll ... solved
  • Next by Date: Re: how do I kill and quit processes/daemons?
  • Previous by thread: Re: providing Apple Help in cocoa app
  • Next by thread: Menu enabling and "_documentWindow"
  • Index(es):
    • Date
    • Thread