2011-02-05 27 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; 
} 

我有這樣的問題