Re: Problem with unbind:
Re: Problem with unbind:
- Subject: Re: Problem with unbind:
- From: Martin Hewitson <email@hidden>
- Date: Sun, 23 Aug 2009 15:25:36 +0200
I've found what may be considered a workaround. I can unbind the
Content Set then use a fetch request and setContent: to get back the
full list. The code looks like:
NSManagedObjectContext *moc = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Entry"
inManagedObjectContext:moc]];
NSError *error = nil;
NSArray *results = [moc executeFetchRequest:request error:&error];
if (error) {
[NSApp presentError:error];
return;
}
[entryArrayController setContent:results];
Not sure this is the most elegant way to do this, but it seems to work.
On Aug 23, 2009, at 11:30 AM, Martin Hewitson wrote:
Dear list,
I've been trying to do some programmatic bindings because I want to
change a binding depending on the state of a check box. In more
detail, I have an NSArrayController whose contents I want to bind to
either all entities of a particular type in the MOC, or to a subset
of those. This is a 'show all' check box.
So far I have tried the following code:
- (IBAction)showAllEntries:(id)sender
{
if([showAllCheckButton state]==NSOnState) {
NSLog(@"Showing all....");
[entryArrayController unbind:@"contentSet"];
} else {
NSLog(@"Showing category entries....");
[entryArrayController bind:@"contentSet"
toObject:categoryArrayController
withKeyPath:@"selection.entries"
options:nil];
}
}
When the app launches, my bound table view shows all entries. When I
uncheck the check box, the table is emptied because none of the
entries has any categories assigned, as yet. Re-checking the check-
box, however, does not yield the full list again. I was hoping that
unbinding the binding would return the array controller to the state
it was before I set the binding, and hence the table view would be
repopulated.
A further detail: the core data model has two entities, an Entry and
a Category. They have a many-many relationship:
categories <<----->> entries
I'm sure I'm going wrong in many ways, and would appreciate any
pointers to get me on the right track. Essentially what I'm aiming
for is that entries can belong to none or many categories. So I want
to be able to show the list of entries that are in one or more
categories, but also I want to show a full list, independent of the
categories (the 'show all' feature).
Best wishes,
Martin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: email@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: email@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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