• 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: Simple question: How do you store a sender's ID?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Simple question: How do you store a sender's ID?


  • Subject: RE: Simple question: How do you store a sender's ID?
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Thu, 8 Apr 2004 17:28:02 -0400

> Scenario:
>
> I have a sender:
>
> - (IBAction)Enter:(id)sender;
>
> I understand that I can change the character & get info from this
> sender via [sender < >]; message.
>
> However, this is only good within the particular sender method.
>
> Suppose I wish to refer to this particular 'sender' in a different
> method within the code?
>
> I need to store the sender's id.
>
> 1) How is that done?
>
> (id) mySender = [[NSObject alloc] initwithname [sender getID]]; <---
> something like this?

No. The sender in the signature of an action method is a regular pointer to
a Cocoa object, typically a UI element like a button or text field. If you
need to refer to that object, you may be able to simply pass the sender as
an argument. For instance, if your action method relies on another method,
the other method could look something like this:

- (NSString *)helpWithSender:(id)sender
{
NSString *result;
//do stuff here
return result;
}

and you would call it from the action method like this

- (IBAction)yourAction:(id)sender
{
NSString *theHelp = [self helpWithSender:sender];
}

You also could set up an instance variable, with a setter and getter method,
and pass the sender to the setter.

[self setTextFieldThatSentAction:sender];

The setter would retain the sender and release it when done. Make sure to
dealloc properly to avoid leaks.

>
> Eventually, in a separate method, I would like to access this
> particular sender (button/field whatever):
>
> [<sender id> setTitle:@"Area Code:"]; <-- but I need to replace
> 'sender' with 'mySender', since 'sender' is local scope.

You would do [[self textFieldThatSentAction] setTitle:@"Area Code"];

Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Simple question: How do you store a sender's ID?
      • From: Andreas Mayer <email@hidden>
References: 
 >Simple question: How do you store a sender's ID? (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: Getting font color change messages in view
  • Next by Date: Re: [OT] Debugger protection (was: Implementing Licensing ...)
  • Previous by thread: Simple question: How do you store a sender's ID?
  • Next by thread: Re: Simple question: How do you store a sender's ID?
  • Index(es):
    • Date
    • Thread