Custom NSView Subclass and Bindings
Custom NSView Subclass and Bindings
- Subject: Custom NSView Subclass and Bindings
- From: Alan Donsky <email@hidden>
- Date: Sat, 6 Mar 2004 11:02:58 -0600
I am at wits end!
Has anyone successfully created a NSView subclass that works with
bindings?
I can get it to mostly work in that my view correctly updates itself
when the model changes, but i cannot figure out how to make changes in
the custom view affect the model. Simply using accessors does NOT
work.
I even did a simple experiment to try and localize the problem. I
tried to make a NSTextField subclass that basically does the exact same
thing as a text field. I named the class FooView and it has a single
instance varible foo, which is an NSString.
Next i wrote accessors:
-(NSString *) foo {return foo;}
-(void) setFoo:(NSString *) newFoo
{
[newFoo retain];
[foo release];
foo = newFoo;
[[self cell] setStringValue:foo];
}
I dragged a text field to the window, changed its class to FooView.
I manually bound it to an objectController and it works perfectly. Any
changes in the model lead to the appropriate accessor methods in
FooView to be called.
Now i want it so that if the user types in the text field, it will
change the model. So i added
- (void)textDidChange:(NSNotification *)notification
{
NSTextFieldCell *c = [self cell];
NSString *s = [c stringValue];
[self setFoo:s];
}
But it does not work. When the user types, the method is called, and
the instance variable foo is changed, but the model is not changed! I
checked this very cafefully.
Now i thought that maybe it has to do with manual bindings or
something, so i dragged a NSTextField to the window. Then i manually
bound it to the same object controller using the same exact bind: call.
But that one works perfectly, so that typing in the text field causes
changes to the view.
I think i understand this stuff on a high level, but i am perplexed.
Thanks
alan
_______________________________________________
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.