Re: Binding/KVO question
Re: Binding/KVO question
- Subject: Re: Binding/KVO question
- From: "Kyle Sluder" <email@hidden>
- Date: Wed, 3 Dec 2008 17:27:43 -0500
On Wed, Dec 3, 2008 at 4:35 PM, Jean-Nicolas Jolivet
<email@hidden> wrote:
> An AppController with a bunch of properties (lets say propA, probB and
> probC, all integers) that are bound to my main window's controls... (all
> sliders..) when the main windows sliders are changed, the properties of
> AppControllers are changed...
You probably shouldn't be doing this. You should instead bind your UI
elements to an instance of an NSController subclass, and then bind
that controller to the AppController.
Speaking of which, is AppController really a good name for what it's
doing? Or is it really just an NSApplication delegate?
> In the same NIB file I have a second window with a custom view inside (Let's
> call it MyCustomView, in MySecondWindow) is there a way for MyCustomView to
> have properties that will be bound to my AppController's propA, propB and
> propC so that MyCustomView is also notified when those properties are
> changed?
A few things here:
1) This second window should probably be in a separate nib.
2) In order to expose bindings on a custom view, you have to package
that custom view in an IB plugin. Good news is that IB3 is much
better about single-project plugins than IB2 was. In those days, you
had to bundle and install your custom views in an IB palette; IB3
should see your plugin in your project and make it available for you
right away.
3) Once you've got that down, you would then bind this view's
properties to an NSController as well.
> I am reading on Key-Value observing right now but it seems like if I want to
> add an observer on my AppController's properties in my CustomView's code I
> would need an instance to my AppController, which I haven't!
If you were able to get to your AppController instance when binding
your sliders, and your other window is in the same nib, how could you
not be able to get a reference to the AppController when setting up
KVO in your custom view? The worst you would have to do is add an
outlet on your view.
> (both MySecondWindow and MyCustomView are outlets of my AppControllers...)
Aha. Following my advice above will introduce a retain cycle unless
you're careful.
--Kyle Sluder
_______________________________________________
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