2015-07-04 30 views
0

我有一個自定義UICollectionReusableView這是一個UICollectionView的標題視圖。這個標題視圖上有一個標籤,我想在標籤上處理一個點擊事件。UICollectionReusableView無法按住拖動UILabel IBAction

出於某種原因,我無法按住CTRL拖動來創建IBAction來處理單擊事件。我也嘗試在視圖的initWithCoder()中向標籤添加UITapGestureRecognizer。儘管initWithCoder()被調用,但當標籤被點擊時,回調永遠不會被調用。

您的幫助將不勝感激!謝謝!

這裏的UICollectionReusableView裏面的代碼:

-(id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [super initWithCoder:aDecoder]; 

    self.tapRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onLabelTap:)]; 
    [self.label1 addGestureRecognizer:self.tapRecogniser]; 

    return self; 
} 

-(void)onLabelTap:(UITapGestureRecognizer *)tapGestureRecognizer; 
{ 
    NSLog(@"Label tapped"); 
} 
+0

你能提供一些代碼嗎?瞭解問題出在哪裏可能很有用。 – LuckyStarr

+0

我試圖使用故事板Ctrl +將標籤拖動到UICollectionReusableView創建一個IBAction。我不知道我應該顯示什麼代碼... – iht

回答

0

userInteractionEnabled屬性的默認值是FALSE該類UILabel。嘗試將其設置爲TRUE

+0

感謝您的快速響應。我確實已經在故事板中設置了這個標誌,但這沒有幫助。 – iht

+0

當xib加載時,您是否嘗試檢查它是否真的設置爲TRUE? – LuckyStarr