• 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: @distinctUnionOfObjects and NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @distinctUnionOfObjects and NSTableView


  • Subject: Re: @distinctUnionOfObjects and NSTableView
  • From: mmalcolm crawford <email@hidden>
  • Date: Sat, 28 May 2005 21:26:50 -0700


On May 28, 2005, at 7:16 AM, Fletcher T. Penney wrote:

I would like to take an NSArrayController that is created from Core Data and use the arrangedObject's (I do a lot of nested predicate building to display only the desired values) to build a list of distinct properties to be placed in a single column table.


Instantiate an array controller ("NamesController") that manages an array of strings. Bind its contentArray to:
[PeopleArrayController]email@hiddenNam e


To your window, add a table view with a single column. Bind the table column's value to
[NamesController].arrangedObjects



Instantiate another array controller ("Filtered Persons") that manages an array of Persons. Bind its contentArray to:
[PeopleArrayController].arrangedObjects
Bind its managedObjectContext to:
[PeopleArrayController].managedObjectContext



In your NSDocument subclass, add the document as an observer of the NamesController's selection:


- (void)windowControllerDidLoadNib:(NSWindowController *) windowController
{
[super windowControllerDidLoadNib:windowController];
[namesArrayController addObserver:self forKeyPath:@"selection" options:nil context:SelectedNameContext];
}



Then implement a suitable observe... method to update the predicate on the Filtered Persons array controller:



- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id) object change:(NSDictionary *)change context:(void *)context
{
if (context == SelectedNameContext) {


NSArray *selectedNames = [namesArrayController selectedObjects];
if ([selectedNames count] == 0) {
[filteredPersonsArrayController setFilterPredicate:nil];
}
else {
NSString *selectedName = [selectedNames objectAtIndex:0];


NSPredicate *newPredicate = [NSPredicate predicateWithFormat:
@"firstName like %@", selectedName];


[filteredPersonsArrayController setFilterPredicate:newPredicate];
}


[filteredPersonsArrayController rearrangeObjects];
return;
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}



Then tidy up:

- (BOOL)windowShouldClose:(id)sender
{
[namesArrayController removeObserver:self forKeyPath:@"selectedObjects"];
return YES;
}



mmalc

_______________________________________________
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


References: 
 >@distinctUnionOfObjects and NSTableView (From: "Fletcher T. Penney" <email@hidden>)

  • Prev by Date: Accessing iTunes
  • Next by Date: Re: Wake from Sleep
  • Previous by thread: @distinctUnionOfObjects and NSTableView
  • Next by thread: WWDC 2005 Suggestion
  • Index(es):
    • Date
    • Thread