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.
使用UIControlEventTouchUpInside事件代替UIControlEventTouchUpOutside事件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.