2012-07-09 66 views
0

我有一個按鈕已被添加到UILabel和該UILabel被添加到UIView和最後該UIView已被添加到滾動視圖。UILable上的UIButton沒有得到點擊

這是我的代碼:

nextBtn=[UIButton buttonWithType:UIButtonTypeCustom]; 
nextBtn.frame=CGRectMake(250, 8, 26, 26);   //2626 
[nextBtn setImage:[UIImage imageNamed:@"disclosure1.png"] forState:UIControlStateNormal]; 
[nextBtn addTarget:self action:@selector(nextBtnClkd) forControlEvents:UIControlEventTouchUpInside]; 
[reviewLabel addSubview:nextBtn]; 
[middleView addSubview:reviewLabel]; 
[mScrollView addSubview:middleView]; 
[self.view addSubview: mScrollView]; 

現在nextBtnClkd方法不被調用上按一下按鈕。

請幫幫我。

感謝

回答

1

請問您的UILabel接受交互事件?

reviewLabel.userInteractionEnabled = YES; 
+0

謝謝,其工作 – 2012-07-09 09:41:52

2

顯示你的標籤和middleView代碼。

nextBtn=[UIButton buttonWithType:UIButtonTypeCustom]; 
nextBtn.frame=CGRectMake(250, 8, 26, 26); 
[nextBtn setImage:[UIImage imageNamed:@"disclosure1.png"] forState:UIControlStateNormal]; 
[nextBtn addTarget:self action:@selector(nextBtnClkd) forControlEvents:UIControlEventTouchUpInside]; 



[nextBtn addSubview:reviewLabel]; //Add label on Btn. 
[middleView addSubview:nextBtn]; 
[mScrollView addSubview:middleView]; 
[self.view addSubview: mScrollView]; 
0

標籤的用戶交互被設置爲NO。所以首先設置YES。

reviewLabel.userInteractionEnabled=YES;