title: Can't get UITouch event from UIButton
body: <p>Problem:</p>
  
  <p>I can't get my UIButton to send my Class an Event call</p>
  
  <p>Here is what I tried first:</p>
  
  <p>I made a class which extends UIViewController, called Viewer</p>
  
  <pre><code>#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
  </code></pre>
  
  <p>then:</p>
  
  <ul>
  <li>I created a class called MainScreen, 2 IBOutlets - singlePlayerButton and view</li>
  <li>Viewer is an instance of UIViewController</li>
  <li>buttonPressed has the return type of IBAction</li>
  </ul>
  
  <p>MainScreen:</p>
  
  <pre><code>#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
  </code></pre>
  
  <p>Then I created an NIB called <code>MainScreenLayout.xib</code></p>
  
  <p>Here is what it looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/yKn8V.png" alt="Screenshot of my NIB file"></p>
  
  <p>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.</p>
  
  <p>Now, I linked the action to the Single-Player button like this:</p>
  
  <p><img src="https://i.stack.imgur.com/otqW6.png" alt="Screenshot of connecting the action to the button"></p>
  
  <p><code>buttonPressed</code> 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 <code>buttonPressed</code> 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:</p>
  
  <p><img src="https://i.stack.imgur.com/39DWp.png" alt="Screenshot of First Responder Window"></p>
  
  <p>Now, I thought at this point it should work. I ran it on my iPhone Simulator and pressed the button. </p>
  
  <p>Just so there is no question of whither or not I'm competent, here is a picture of me actually clicking the button:</p>
  
  <p><img src="https://i.stack.imgur.com/CNjDX.png" alt="Screenshot"></p>
  
  <p>I got no output whatsoever. Then I went to my code and looked at the method. This is what it looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/kawmX.png" alt="Screenshot of method"></p>
  
  <p>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:</p>
  
  <pre><code>- (IBAction)aVerySpecificMethodNameForMyButtonListener:(id)sender
  {
      NSLog(@"A button was pressed!");
  }
  </code></pre>
  
  <p>Then I went back to my NIB window, unpaired my Single-Player button and then repaired it to <code>aVerySpecificMethodNameForMyButtonListener</code>. Now this is what it looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/IP1Mx.png" alt="Screenshot for rediculous method name"></p>
  
  <p>Then I ran it again and still nothing when I pressed the button. Then I went back to the code:</p>
  
  <p><img src="https://i.stack.imgur.com/scMBL.png" alt="Screen shot"></p>
  
  <p>(insert frustration here)</p>
  
  <p>At this point I restarted Xcode and the Simulator and looked over everything again and it still didn't work.</p>
  
  <p>This is what I tried next which seems about a billion times more simple:</p>
  
  <pre><code>- (void)show
  {
      [[NSBundle mainBundle] loadNibNamed:@"MainScreenLayout" owner:self options:nil];
      [viewer.view addSubview:view];
  
      [singlePlayerButton addTarget:self action:@selector(aVerySpecificMethodNameForMyButtonListener:) forControlEvents:UIControlEventTouchUpInside];
  }
  </code></pre>
  
  <p>I replaced with my <code>show</code> 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:</p>
  
  <pre><code>(lldb) 
  </code></pre>
  
  <p>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.</p>
  
  <p>Does anybody see what I'm doing wrong here? Is it just Xcode being flakey?</p>
  
  <p>Thanks for reading!! All relevant answers are welcomed!</p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>I also tried changing the declaration of UIButton to a property in the Header file:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #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
  </code></pre>
  
  <p>Thus here is what I changed in MainScreen.m to comply:</p>
  
  <pre><code>#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
  </code></pre>
  
  <p>Now there are no variable declarations inside of the MainScreen.m file, I moved them all to the Header. The circles next to <code>singlePlayerButton</code> and <code>view</code> are still filled in but the bubble next to the method is not. I ran the code again and got the same output.</p>