title: iPhone SDK 2: Programmatically adding an Info Button
body: <p>I am trying to add an info button to my app to provide custom help. </p>
  
  <p>Instead of adding the button to the nib and linking the event (touchUpInside) to the controller, I decided to add the button programmatically. The button shows up. When I add the target event handler to be executed when the button is touched, it does not work. That my method(doHelp) is not being called on touching the button.</p>
  
  <p>When I debugged it, the event is not registered with the button! Although the code does not throw any exceptions.</p>
  
  <p>Here is the code snippet FROM the view:</p>
  
  <pre><code>    // Create a Button to get Help      
      UIButton *helpButton =  [UIButton buttonWithType:UIButtonTypeInfoDark ] ;
      buttonRect = helpButton.frame;
  
      // CALCulate the bottom right corner
      buttonRect.origin.x = rect.size.width - buttonRect.size.width - 8;
      buttonRect.origin.y = rect.size.height - buttonRect.size.height - 8; 
      [helpButton setFrame:buttonRect];
  
      [helpButton addTarget:self action:@selector(doHelp:) forControlEvents:UIControlEventTouchUpInside];
      [helpButton setEnabled:TRUE];
      [self addSubview:helpButton];
  </code></pre>
  
  <p>........</p>
  
  <pre><code>// Another METHOD ELSEWHERE in the VIEW object
  -(void)doHelp:(id)Sender
  {
      [self setHelpNeeded:TRUE];
      [self setNeedsDisplay];
  }
  </code></pre>
  
  <p>What am I doing wrong please? 
  I have looked at the SDK help and samples and am really flummoxed!
  Am hoping another pair of eyes will help! :-)</p>
  
  <p>This code snippet is in the View Object in case you need to know.
  I just added the doHelp to help the first 2 responders... thanks.</p>
  
  <p>**UPDATE 6/4/09 ** -
  I have been trying all night and nothing worked.  I think there is something wrong in the way I have set up the method selector as my method never gets called. Everything else looks fine. Even using a NIB file does not work. I have tagged the button, retrieved it and added the method selector but to no avail.  There is something fundamental which I am doing wrong... Argh!!!
  <em>Any ideas, anyone?</em></p>