Re: NSApp sendAction
Re: NSApp sendAction
- Subject: Re: NSApp sendAction
- From: Shawn Erickson <email@hidden>
- Date: Wed, 23 Nov 2005 09:03:03 -0800
On 11/23/05, Brian O'Brien <email@hidden> wrote:
> Hi. I'm trying to use NSApp sendAction.
> However I don't seem to be able to pass parameters to the selector.
> For example...
> [NSApp sendAction:@selector(seriesReceivedInArray:dataSets
> fromPort:portnumber) to:reply from:self];
> won't compile I get the error message
> err: expected `:' before 'fromPort'
>
> However
> [NSApp sendAction:@selector(seriesReceivedInArray:) to:reply
> from:self];
>
> complies without error.
> Maybe I have a syntax error and am not calling it properly?
The sendAction method of NSApplication follows the target / action
paradigm used heavily for traditional communication between UI
elements and controllers in your application. An action message is
defined to be of the form someActionMessage:(id)sender. With the
sender usually being the object that sent the action message. It isn't
designed to pass multiple parameters (note sendAction:to:from: does
provide a way to supply such parameters even).
> Previously I was doing:
> [reply seriesReceivedInArray:dataSets fromPort:portNumber];
> but that doesn't work with pyObjC calling a python method.. but that
> I guess is beyond the scope
> of this mailing list....
>
> So does anyone know how I can pass parameters to selector using NSApp
> sendAction?
You don't. The expectation that the selector you supply follows that
of an action message which should have just the one parameter which is
implied to be the sender of the message (doesn't have to be). You can
code things such that the target of an action can extract the state it
needs from the sender object. This is in fact what is often done when
getting and action message from a UI element, the target exacts the
state from the sender (for example gets the controls current value).
> How about performSelctorOnMainThread? How might I use that? Or
> shouldn't I?
Hard to answer without really understanding the problem you are
attempting to solve.
The performSelectorOnMainThread: method does what the docs say it
does, it is meant as a way to get an certain object to respond to a
certain selector with the option to pass a single object as part of
the message and have that message be processed on the main thread.
This is used when you need do an operation that needs to be serialized
with other code running on the main thread (most of AppKit runs on the
main thread, under its runloop).
The optional object you can send with the message can be any object
that you want. It could for example be an NSArray instance with
"parameters" related to the message.
Anyway without knowing what you are attempting to solve... consider
leveraging NSInvocation if you have the need to send messages with
multiple parameters but often you should just be able to message
directly as needed.
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden