2011-02-05 29 views
2

我有下面的代码,当我按下UIButton时,没有任何东西被调用,并且不会崩溃。UIButton的addtarget:触摸它后不会调用!

calloutButton = [[UIView alloc] initWithFrame:CGRectMake(left_width2*2-3, 5, 230, 230)]; 
    UIButton *buttongo= [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

    buttongo.frame=CGRectMake(0, -1, 25, 25); 
    [buttongo addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside]; 
    [calloutButton addSubview:buttongo]; 

    [label addSubview:calloutButton]; 




    -(IBAction)buttonEvent:(id)sender 
    { 
      NSLog(@"Hello..."); 
    } 

有人知道为什么吗?

谢谢!

回答

3

检查标签的大小,它可以是CGSizeZero,但由于子视图的裁剪默认为NO,所以按钮是可见的,但它不可触摸。

+0

我有以下。我认为是你的意思。 (( - (left_width2 * 2 + 21)/ 2)-21,19 - ANCHOR_Y,100,CALLOUT_HEIGHT)]; label.backgroundColor = [UIColor brownColor]; Brown Color在标签 – saimonx 2011-02-05 19:23:16

0

确保你没有

@property IBOutlet UIButton *yourButton; 

与同名

@implementation { 
    UIButton *_yourButton; 
} 

我有这样的问题