• 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: Stupid question: selected object of an array controller
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid question: selected object of an array controller


  • Subject: Re: Stupid question: selected object of an array controller
  • From: Pierre Bernard <email@hidden>
  • Date: Sun, 13 Jun 2004 21:22:20 +0200

Chris,

thanks a bunch for your help. Works like a charm!

Pierre

On Jun 4, 2004, at 8:42 PM, Chris Giordano wrote:

Pierre,

On Jun 4, 2004, at 1:12 PM, Pierre Bernard wrote:

Hi!

I have created using bindings what essentially is a master detail interface. I have a NSArrayController which draws its content from the file owner. I have a table view whose columns bind to keys of the controller's arranged objects. The table allows only for single selection and there is a detail part in the UI to display said selection.

Now I would like my NSDocument subclass to know which item is selected. I actually want it to be 'notified' when the selection changes. I guess this should be trivial. Yet I am at loss.

I see no adapted binding from within Interface Builder. I have tried the following from the windowControllerDidLoadNib: method

[self bind:@"selectedPage" toObject:[self pageRollController] withKeyPath:@"selection" options:nil];

Any insight is appreciated.

Thanks in advance!


First, I'm certainly no expert here, but I have recently done something similar.

One thing I noticed quickly was the binding in NSTableView for "selectionIndexes". I haven't tried this approach, but it might work to let you notice when there are changes.

However, it may be more straightforward to just observe changes to the selection rather than binding to something in the controller. Binding - to me at least - seems to indicate a bi-directional flow of information, whereas adding an observer is the "one-way" equivalent.

In a project that I have, I just tell the controller to add my object as an observer to watch changes in the selection. The equivalent for you should be something like the following:

[[self pageRollController] addObserver:self forKeyPath:@"selection" options:0 context:nil];

I then observe the value changes and act appropriately. Again, adapting it to your example above, you'd do something like the following:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context;
{
if ((object == [self pageRollController]) && [keyPath isEqualToString:@"selection"])
{
// do what you wanted to in response to changes
}
}


Hope this helps.

chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Stupid question: selected object of an array controller (From: Pierre Bernard <email@hidden>)
 >Re: Stupid question: selected object of an array controller (From: Chris Giordano <email@hidden>)

  • Prev by Date: Re: NSFontPanel problem
  • Next by Date: Re: Cocoa and resource forks
  • Previous by thread: Re: Stupid question: selected object of an array controller
  • Next by thread: Changing an NSImageView's NSImage
  • Index(es):
    • Date
    • Thread