Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:38:02+00:00 2026-05-24T12:38:02+00:00

there is a similar question in here but for some reason I cannot make

  • 0

there is a similar question in here but for some reason I cannot make it work.

I am creating a lot of buttons so I am creating them dynamically with code. so the following code creates a button that when on touchdouwn it executes the aMethod:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
           action:@selector(aMethod)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Hello" forState:UIControlStateNormal];
button.frame = CGRectMake(40.0, 200.0, 170.0, 40.0);
[self.view addSubview:button];

-(void) aMethod{
   //code
}

in the aMethod I want to know wich button was pressed because many buttons point to that method. as a result I need my aMethod to look like:

-(void) aMethod:(id) sender{
   //code
}

if I change the aMethod then I have to change the selector for:

[button addTarget:self 
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchDown];

when I click on the button I get an error. so from reading the post on the first link that I posted I found out that the selector will pas a button so I tried changing aMethod to:

-(void) aMethod:(UIButton*) sender{
       //code
    }

and I still get an error. How can I pass the button with the selector?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:38:03+00:00Added an answer on May 24, 2026 at 12:38 pm

    I don’t quite understand what you’re asking but ID is an arbitrary object that represents some other object (think dynamic typing?). Don’t change the datatype on your selector method from ID to anything else.

    If it is a method that is fired by UIButtons, then you access the button like this:

    -(void) aMethod:(id)sender {
    UIButton *pressedButton = (UIButton *)sender;
    }
    

    Now you have the UIButton object for whatever button triggered the selector method to be fired.

    One way to tell which button fired the selector, give them tags then inspect the tag in your aMethod:. After making a pointer to the button object using the code above you’ll have access to pressedButton.tag

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a similar question here but it only covers some of the issues
I know there is a very similar question here but I was hoping to
There seems to be a similar question to this on here but with the
I see there is a similar question asked here but I don't think it
There is similar question to this one here but I guess that by this
I am aware that there is a similar question here with no solution. I'm
Yes, there is a similar question here . However, that question doesn't seem to
I had a similar question answered Here There is a slight twist to the
This is a question similar to a question here . I wonder is there
There are similar question, but not regarding C# libraries I can use in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.