2012-11-20 71 views
1

在我的應用程序中,我添加了UIImageviewUIViewUIButton添加到該UIImageView。該按鈕不響應觸摸事件,並且不調用動作選擇器。爲什麼?按鈕沒有響應觸摸

回答

3

因爲UIImageView默認情況下將其userInteractionEnabled屬性設置爲NO。將其設置爲YES,它會起作用。

+0

這又是一個愚笨不一致UIKit中,順便一提。這是故意的,但它比好的更令人困惑。 – 2012-11-20 07:44:02

0

確保您已將IBAction附加到您的按鈕上。然後檢查是否啓用了用戶交互。

0

試試這個來解決它。

UIIMageView *image; 
image.userInteractionEnabled=YES; 

希望這有助於任何一個

阿米努

0

首先你添加的ImageView然後添加按鈕,然後按鈕是否工作正常這樣的代碼

UIView *AddView=[[UIView alloc]initWithFrame:CGRectMake(55, 0, 100, 100)]; 
UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; 


       UIButton *btnRemove = [[UIButton alloc]init]; 
       UIImage *btnImage = [UIImage imageNamed:@"close.png"]; 
       [btnRemove setImage:btnImage forState:UIControlStateNormal]; 
       [btnRemove addTarget:self 
           action:@selector(btnREmoveAction:) 
        forControlEvents:UIControlEventTouchUpInside]; 
       btnRemove.frame = CGRectMake(0,0, 29, 29); 

       btnRemove.tag=indexStart; 

       [AddView addSubview:imgview]; // add the imageview 
       [AddView addSubview:btnRemove]; // add the button