0

I have a custom view, for example ParentView : UIView. Inside this view I have one UIButton that I'm adding programatically as

UIButton *btn = [[UIButton alloc] initWithFrame:frame];
        [btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpOutside];
    [self addSubview:btn];

and the action:

-(void)buttonPressed:(id)sender{
    NSLog(@"button pressed: %@",sender);
}

In my storyboard I have a basic View, whose class I've set to ParentView. The initialization is indeed called, and the UIButton is created fine, just the action is not called. The ParentView has userInterActionEnabled checked.

Axarydax
  • 16,353
  • 21
  • 92
  • 151

1 Answers1

4

Use UIControlEventTouchUpInside event instead of UIControlEventTouchUpOutside.

Igor Matyushkin
  • 778
  • 4
  • 4