开发者

subView's touchesBegan: withEvent: selector not called

开发者 https://www.devze.com 2023-03-29 22:59 出处:网络
In the following code, I created a MTLabel object and a UIButton object, changed their frame, then add UIButton as subView of \'MTLabel\'

In the following code, I created a MTLabel object and a UIButton object, changed their frame, then add UIButton as subView of 'MTLabel'

MTLabel* label = [MTLabel labelWithTitle:title];
label.frame = ...
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
                action:@selector(didSelectStore:)
      forControlEvents:UIControlEventAllEvents];
[label addSubview:rightButton];
rightButton.frame = ...;
[an addLabel:label];

After that both UIViews appears on screen, howeverdidSelectStore: is never called when touching that rightButton.

As MTLabel is defined in a third-party lib, I don't have it's source code. So I write a category like this:

@implementation MTLabel(button)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
}
......
@end

After doing that, [rightButton touchesBegan:event:] is still not called, not mention that action.

So the touch events are not working as expected in that subView.

Any idea on how then happen and what s开发者_JAVA技巧hould I do?

Thank you.


I don't think you need to create a category and add touchesBegan: to make this work. Have you ensured that label.userInteractionEnabled = YES;?

0

精彩评论

暂无评论...
验证码 换一张
取 消