• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: multiple targets/selectors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple targets/selectors


  • Subject: Re: multiple targets/selectors
  • From: "John C. Randolph" <email@hidden>
  • Date: Wed, 26 Dec 2001 04:59:34 -0800

On Wednesday, December 26, 2001, at 04:35 AM, Sven A. Schmidt wrote:

> In the little app that I'm working on I've encountered the
> following problem:
>
> I've got a menu from which I'd like to trigger messages in more
> than one object. From what I gather, I can set one target and
> one action, and I could surely work around this problem but it
> would be a lot more elegant to trigger two different
> targets/actions directly.
>
> To be a bit more specific:
>
> I have a server object that controls a global menu. The items
> in that menu are connected to the clients (to their "quit"
> action). Now, I'd like the server to know when the clients are
> getting the quit message. Like I said, it's easy to think of
> work-arounds:
> a) send a message from the client that it's quitting
> b) connect the items to the server and have it pass on the
> message to the clients
>
> I don't like (b) that much (for a lot of reasons that all boil
> down to being lazy). (a) is easy to do, but I've got the
> connection right there and it seems like taking an extra corner
> from the menu to the client to the server when I'm almost there
> already. Plus, there might be occasions when it's not that easy.
>
> So, is there some message cascading available in obj-c that I'm
> not aware of or is it just considered bad design to distribute
> messages without a proper control object?

The way we do this kind of thing these days is with the
NSNotification class, which effectively lets you "broadcast" a
message. In the case you describe, the client should post an
"I'm quitting!" notification, and any other object that cares if
a client is quitting should register for those notifications.

-jcr



"The right to be heard does not include the right to be taken
seriously." - Hubert Humphrey


References: 
 >multiple targets/selectors (From: "Sven A. Schmidt" <email@hidden>)

  • Prev by Date: Re: Adding carriage-return behavior to NSTextView
  • Next by Date: Re: Sheet from another nib
  • Previous by thread: multiple targets/selectors
  • Next by thread: Zones, [[alloc] init], and all the new + methods
  • Index(es):
    • Date
    • Thread