title: Programmatically created button not firing event in custom view in iOS
body: <p>On iOS, I created a button programmatically but the event is not firing.</p>
  
  <pre><code>UIButton * anyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  [anyButton addTarget:self action:@selector(handleAnyButton:) forControlEvents:UIControlEventTouchUpInside];
  anyButton.frame = CGRectMake(150, 350, 22, 22);
  [self addSubview:anyButton];
  </code></pre>
  
  <p>The code is placed inside a custom view (not custom view controller), but I cannot make it fire the event. The press animation is not showing. The custom view has userInteractionEnabled enabled. I also tried using storyboard to create another button on the same view and that one is working. The button code is done in initWithFrame. Must be some simple error I haven't caught and I have been pounding my head over this one for hours.</p>
  
  <p>EDIT:</p>
  
  <p>The event handler:</p>
  
  <pre><code>-(void) handleAnyButton:(UIButton *)button
  {
      NSLog(@"handleAnybutton called");
  }
  </code></pre>
  
  <p>EDIT2:
  The above button codes is done within a [self setup] of class PKLocationsSelectionView.</p>
  
  <pre><code>- (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if (self) {
          // Initialization code
          [self setup];
      }
      return self;
  }
  </code></pre>
  
  <p>And this view was created programmatically within the view controller (PKLocSelectionViewController) responsible for this hierarchy:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
  
      CGFloat fieldsHeight = 88;
      UIView * view = [[PKLocationsSelectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, fieldsHeight)];
  
      [self.view addSubview:view];
  }
  </code></pre>