Re: Programmatic Binding
Re: Programmatic Binding
- Subject: Re: Programmatic Binding
- From: Richard Somers <email@hidden>
- Date: Tue, 18 May 2010 16:21:10 -0600
On May 18, 2010, at 1:40 PM, Quincey Morris wrote:
<sigh> If you want an answer, you're going to have to be a bit more
forthcoming with information.
Is "foo" an instance variable or a property? If instance variable,
what's the value of accessInstanceVariablesDirectly for its class?
If a property, is there an @property declaration, and how are its
getter and setter defined?
Have you verified whether setFoo: is never called, or whether it's
called with the wrong value? Is the setter called when you
subsequently change the user default value that foo is bound to? How
do you know that the user default value is correct? Just knowing
that foo has the wrong value at some point isn't much help in
tracking down the problem.
Thanks for being patient and helpful. Foo is an ivar with a getter and
setter, so that makes it a property.
@interface MyCustomLayer : CAOpenGLLayer
{
@private
int _foo;
}
@end
@implementation MyCustomLayer
- (int)foo
{
return _foo;
}
- (void)setFoo:(int)foo
{
_foo = foo;
// When foo is changed update the size of the layer.
CGFloat size = (2 * foo) + 1;
[self setFrame:CGRectMake(0.0, 0.0, size, size)]; // This is
where the problem occurs!
}
@end
I have verified that the setter 'setFoo' is being called in all cases
so that is not the problem as I originally thought.
In 'awakeFromNib' when 'bindFoo' is called before 'setView' the layer
frame is set but never actually changes to the set value! So the
problem is not one of binding but of layer initialization.
The user default value of foo is 8 which means the first time through
'setFoo' sets the layer frame width and height to 17. But the layer
frame width and height never actually get changed but are a value of 1
(not sure where that comes from) which for me is a non-operational
layer and causes other problems.
If the user defaults changes and sets the value of foo a second time
(after awakeFromNib) then the layer frame width and height gets
properly set and all is well.
So to recap.
// In awakeFromNib this works. Layer frame is set to correct
value.
layer = [[MyCustomLayer alloc] init];
[layer setView:self];
[layer bindFoo];
...
// In awakeFromNib this does not work. Layer frame does not
properly set.
layer = [[MyCustomLayer alloc] init];
[layer bindFoo];
[layer setView:self];
...
I have also tried the following.
layer = [[MyCustomLayer alloc] init];
// Do something else here. But the only thing so far
// that works is [layer setView:self]
[layer bindFoo];
...
Note that I have also tried changing foo from an int to a NSNumber but
it makes no difference. The layer initialization is very
temperamental. Originally the layer was in a nib which worked fine. I
have been refactoring and cleaning up and moving things out of the nib
that do not really belong there. That is when I ran into this problem.
It makes me a little nervous that the layer initialization is so
temperamental.
--Richard
_______________________________________________
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