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 9270185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:18:25+00:00 2026-06-18T15:18:25+00:00

I am trying to create a simple button, textfield, label program in objective c

  • 0

I am trying to create a simple button, textfield, label program in objective c and I am having button problems.

In file viewController.m, I have the following code:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchDown];

[button setTitle:@"Look up" forState:UIControlStateNormal];
button.frame = CGRectMake(20,108,97,37);
[self.view addSubview:button];

and

- (IBAction) buttonPressed:(id) sender  {
[_textField resignFirstResponder];
_label.text = textField.text;
}

From what I understand, the button is supposed to to take what is in my text box and put it into a label after I click this button. But instead, pressing the button takes me main.m on the return line. And it says the program is paused. If I try to use the program again, it just doesn’t work. I have cross examined this button snippet with other code online and can’t quite figure out why mine is failing.

  • 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-06-18T15:18:26+00:00Added an answer on June 18, 2026 at 3:18 pm

    You have missed a colon on this line

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

    Your button is calling a method that doesn’t exist, thats why it is crashing.

    should be

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

    OR… change the signature of your buttonPressed method from

    - (IBAction) buttonPressed:(id) sender;
    

    to

        - (IBAction) buttonPressed;
    

    you should have seen a message in your log, something like

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController buttonPressed]: unrecognized selector sent to instance
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple program that does the following: A service (NewsService)
I am trying to create simple user registration form. I have an index.html file
I'm trying to create a simple button that deletes a row from the database.
I'm trying to create a simple widget to retrieve a users feeds, I have
I am trying to create a simple image link button that when I move
I am trying to create simple CRUD application. I have a partial view that
I'm trying to create a simple dynamic gallery with a radio button under each
I am trying to create a simple html file containing the monthly salary of
I am trying to create a simple html file containing the monthly salary of
I'm trying to create a simple button to open/close a collapsible part of 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.