Iphone sdk 3.0 UIScrollView上的UIButton可以';行不通

Iphone sdk 3.0 UIScrollView上的UIButton可以';行不通,iphone-sdk-3.0,Iphone Sdk 3.0,通过这种方式按钮工作(调用show:),但使用[myLabel addSubview:myButton]按钮不起作用。不知道为什么 ----------------编辑和解决方案------------ 谢谢@KennyTM 默认情况下,UILabel不处理任何事件。您需要将标签的userInteractionEnabled属性设置为YES 此外,您最好不要在UILabel的顶部添加UIButton 默认情况下,UILabel不处理任何事件。您需要将标签的名称设置为“是” 按钮不应该是标签的子视

通过这种方式按钮工作(调用
show:
),但使用
[myLabel addSubview:myButton]按钮不起作用。不知道为什么

----------------编辑和解决方案------------ 谢谢@KennyTM


默认情况下,UILabel不处理任何事件。您需要将标签的
userInteractionEnabled
属性设置为
YES


此外,您最好不要在UILabel的顶部添加UIButton

默认情况下,UILabel不处理任何事件。您需要将标签的名称设置为“是”


按钮不应该是标签的子视图,这是不合逻辑的。将它们都设置为UIView的子视图。

谢谢,只要认为它们都是UIView的子类。@william:UILabel是UIView的子类,只是它显式地关闭了
userInteractionEnabled
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 180)];
myLabel.backgroundColor = [UIColor greenColor];
[self.view addSubview:myLabel];

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self addTarget:self action:@selector(show)  forControlEvents:UIControlEventTouchDown];
myButton.frame = CGRectMake(80.0, 120.0, 30, 30);
myButton.showsTouchWhenHighlighted = YES;
[self addSubview:myButton];