On Feb 2, 2012, at 11:13 , Erik Stainsby wrote:

> I have a context menu in one window (A) from which I need to dispatch to
> another (B) window's First Responder list.
> Do I need to bring in a reference to window B (or it's controller) into the
> nib/code of window A ? This seems to go against loose coupling practices,
> no?  Or should this sort of communication be handled using
> NSNotificationCenter services?

If you mean that window A is in front of window B, then B doesn't have a "First 
Responder list". (There is still a responder chain running through B, but 
there's no way AFAIK of dispatching to this chain through any standard 
mechanism, not while B's behind A.) This means that your application is going 
to have supply the linkage to B manually.

One way, I think, would be to implement the menu's action in your app delegate, 
and in IB target the action to First Responder (i.e. nil). When the menu item 
is invoked, the app delegate's implementation will be invoked, since nothing 
lower down in the responder chain will recognize the action, and the app 
delegate can pass the action on to B. This means that B must inform the app 
delegate of its existence, or that the app delegate must have some other way of 
finding B.

If A needs to include a parameter for B to use, then you'll need to implement 
the menu's action message in A itself, but A can then send a non-action message 
to the app delegate similar to the above.

This should all be simple if there's a single B for the application. If there 
can be different Bs at different times, it's a bit more trouble to do.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to