Updating Core Data model object with an NSButtonCell
Updating Core Data model object with an NSButtonCell
- Subject: Updating Core Data model object with an NSButtonCell
- From: Jake <email@hidden>
- Date: Sat, 16 Oct 2010 18:23:38 -0500
Hi everyone,
I have an NSOutlineView that is backed by a NSTreeController, which is bound
to a Core Data entity. One column in the outlineView is for the entity's
displayName, and the other column is an NSButtonCell. There is an
NSButtonCell for every row in the outlineView.
When a certain row's button is clicked, I would like to trigger a method in
that entity's class to set a variable in the entity. The problem is that
when I call the method, the variable changes seem to be made, but when I
click the button again, the variable is set as the same value it was before.
This leads me to believe that the value of the variable is actually
changing, but for some reason it is not "sticking" (i.e. I'm not performing
the method on the correct object or a proxy of that object or something).
Here's a screenshot to illustrate this in my app:
http://dl.dropbox.com/u/5232448/window.png
And here's the code in my subclass of NSTreeController that the NSButtonCell
is calling:
- (void) toggleTail:(id)sender {
// Getting position and File object in row where button was clicked.
NSInteger position = [outlineView clickedRow];
File *fileAtIndex = [[self flattenedContent] objectAtIndex:position];
// If the file is tailing, stop it (and vice versa).
// TODO: This doesn't work; it always stops.
NSLog(@"Beginng of controller toggle: %@", [[fileAtIndex isTailing]
stringValue]);
[fileAtIndex toggleTail];
NSLog(@"End of controller toggle: %@", [[fileAtIndex isTailing]
stringValue]);
}
And here's the toggleTail method in my entity class:
- (void)toggleTail {
NSLog(@"Beginng of model toggle: %@", [[self isTailing] stringValue]);
if ([[self isTailing] boolValue]) {
[self stopTail];
} else {
[self startTail];
}
NSLog(@"End of model toggle: %@", [[self isTailing] stringValue]);
}
And, finally here are the startTail and stopTail methods in the entity
class:
- (void)startTail {
NSLog(@"Tail started for %@.", [self displayName]);
...
// Updating the record to indicate the file is tailing.
[self setValue:[NSNumber numberWithBool:YES] forKey:@"isTailing"];
}
- (void)stopTail {
NSLog(@"Tail stopped for %@.", [self displayName]);
...
[self setValue:[NSNumber numberWithBool:NO] forKey:@"isTailing"];
}
As you can see, I have log messages scattered about through here in an
attempt to figure out exactly where the bug is. Here is the result of the
log messages:
2010-10-16 18:06:34.865 Tailr[95389:a0f] Beginng of controller toggle: 1
2010-10-16 18:06:34.865 Tailr[95389:a0f] Beginng of model toggle: 1
2010-10-16 18:06:34.866 Tailr[95389:a0f] End of model toggle: 0
2010-10-16 18:06:34.866 Tailr[95389:a0f] End of controller toggle: 0
The log messages are the same every time I click the button. Can anyone
please help me out? I'm kind of running out of ideas on my end. Thanks in
advance, and sorry for the data overload; just thought I'd be thorough in my
explaination.
--Jake
_______________________________________________
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