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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:03:03+00:00 2026-06-16T14:03:03+00:00

Problem: I can’t get my UIButton to send my Class an Event call Here

  • 0

Problem:

I can’t get my UIButton to send my Class an Event call

Here is what I tried first:

I made a class which extends UIViewController, called Viewer

#import "Viewer.h"
#import "MainScreen.h"

@implementation Viewer

- (void)viewDidLoad
{
    MainScreen* main = [[MainScreen alloc]init: self];
    [main show];

    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

then:

  • I created a class called MainScreen, 2 IBOutlets – singlePlayerButton and view
  • Viewer is an instance of UIViewController
  • buttonPressed has the return type of IBAction

MainScreen:

#import "MainScreen.h"
#import "Viewer.h"

@implementation MainScreen
{
    IBOutlet UIButton* singlePlayerButton;
    IBOutlet UIView* view;

    Viewer* viewer;
}

- (id)init:(Viewer*) theViewer
{
    self = [super init];
    viewer = theViewer;
    return self;
}

- (void)show
{
    [[NSBundle mainBundle] loadNibNamed:@"MainScreenLayout" owner:self options:nil];
    [viewer.view addSubview:view];
}

- (IBAction)buttonPressed:(id)sender
{
    NSLog(@"A button was pressed!");
}

@end

Then I created an NIB called MainScreenLayout.xib

Here is what it looks like:

Screenshot of my NIB file

As you can see, I have four buttons but the only one that is connected to anything is the Single-Player button I also have the UIView connected to view.

Now, I linked the action to the Single-Player button like this:

Screenshot of connecting the action to the button

buttonPressed is my method that I want to have called when the button is pressed, so I ctrl-clicked on First Responder and then clicked on the circle next to buttonPressed and then dragged it on top of the Single-Player button. Then the next dialog window popped up and I clicked on Touch up Inside. Here is what the Received Actions window looks like:

Screenshot of First Responder Window

Now, I thought at this point it should work. I ran it on my iPhone Simulator and pressed the button.

Just so there is no question of whither or not I’m competent, here is a picture of me actually clicking the button:

Screenshot

I got no output whatsoever. Then I went to my code and looked at the method. This is what it looks like:

Screenshot of method

as you can see, the oval is not filled, meaning that the method is not paired. So naturally I thought it was being overridden by another method. So here is what the method looks like now:

- (IBAction)aVerySpecificMethodNameForMyButtonListener:(id)sender
{
    NSLog(@"A button was pressed!");
}

Then I went back to my NIB window, unpaired my Single-Player button and then repaired it to aVerySpecificMethodNameForMyButtonListener. Now this is what it looks like:

Screenshot for rediculous method name

Then I ran it again and still nothing when I pressed the button. Then I went back to the code:

Screen shot

(insert frustration here)

At this point I restarted Xcode and the Simulator and looked over everything again and it still didn’t work.

This is what I tried next which seems about a billion times more simple:

- (void)show
{
    [[NSBundle mainBundle] loadNibNamed:@"MainScreenLayout" owner:self options:nil];
    [viewer.view addSubview:view];

    [singlePlayerButton addTarget:self action:@selector(aVerySpecificMethodNameForMyButtonListener:) forControlEvents:UIControlEventTouchUpInside];
}

I replaced with my show method with the one above. The only thing different is the last line. I disconnected my method from the Single-Player button in the NIB. Then I ran it and I got excited for a second because I got some output. Here is what I got:

(lldb) 

Very helpful output C debugger, as always. I spent the next few hours on SO trying to find out what I’m doing wrong. I’ve tried countless examples and none of them worked.

Does anybody see what I’m doing wrong here? Is it just Xcode being flakey?

Thanks for reading!! All relevant answers are welcomed!


UPDATE:

I also tried changing the declaration of UIButton to a property in the Header file:

#import <Foundation/Foundation.h>
#import "Viewer.h"

@interface MainScreen : NSObject
{
    IBOutlet UIView* view;

    Viewer* viewer;
}

@property (weak, nonatomic) IBOutlet UIButton* singlePlayerButton;

- (id)init:(Viewer*) theViewer;
- (void)show;
- (IBAction)aVerySpecificMethodNameForMyButtonListener:(id)sender;

@end

Thus here is what I changed in MainScreen.m to comply:

#import "MainScreen.h"
#import "Viewer.h"

@implementation MainScreen

- (id)init:(Viewer*) theViewer
{
    self = [super init];
    viewer = theViewer;
    return self;
}

@synthesize singlePlayerButton;

- (void)show
{
    [[NSBundle mainBundle] loadNibNamed:@"MainScreenLayout" owner:self options:nil];
    [viewer.view addSubview:view];

    [singlePlayerButton addTarget:self action:@selector(aVerySpecificMethodNameForMyButtonListener:) forControlEvents:UIControlEventTouchUpInside];
}

- (IBAction)aVerySpecificMethodNameForMyButtonListener:(id)sender
{
    NSLog(@"A button was pressed!");
}

@end

Now there are no variable declarations inside of the MainScreen.m file, I moved them all to the Header. The circles next to singlePlayerButton and view are still filled in but the bubble next to the method is not. I ran the code again and got the same output.

  • 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-16T14:03:04+00:00Added an answer on June 16, 2026 at 2:03 pm

    So I’d have put this in a comment because its really just a suggestion however I dont have the rep yet so sorry to get your hopes up, but I believe the touch event’s scope is only inside the UIView in which it happens. When the touch up event gets triggered it doesn’t get passed to the UIView’s handler (MainScreen class) and so the event’s listener method does not get called… but that you are able to link it in the interface builder to the button is baffling to me, so i could be way off.

    Anyways, where I think you should go next is to make your MainScreen a UIView object and see what that does for event handling of the buttons in the view.

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

Sidebar

Related Questions

Problem: Can't get Unicode character to print correctly. Here is my grammar: options {
My problem can be found http://www.hykao.com/bbs/defaultpage.php , which can not get a right html
I think that this problem can be sorted using reflection (a technology which I'm
Which problem can cause kill -9 in production application (in linux to be exact)?
Hello! My problem can be described the following way: I have some data which
Problem: can't get image to the screen... ?? I am looking for a methodology
I have tried to understand and use urlencode, but the problem can't be solved.
My problem can be illustrated in the following example code, which sets up a
This problem can maybe be generalized as a class communication problem and maybe there
Environment: Tomcat 7 JNDI Spring-MyBatis No JTA - commons pooling only Problem: Can't get

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.