2017-07-15 33 views
-1

enter image description here按鈕動作頭部分的objÇ

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] 
           initWithTarget:self 
           action:@selector(handleTapGuesture)]; 

[headerView addGestureRecognizer:tap]; 

此代碼不適合我

在我UiCollectionView我在標題部分part..so添加的按鈕,當我點擊更多按鈕我想要那個單元格的索引。

回答

0

請使用下面的代碼

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGuesture)]; 
[tap setNumberOfTapsRequired:1]; 
headerView.tag = section; 
headerView.userInteractionEnabled = YES; 
[headerView addGestureRecognizer:tap]; 

而且在handleTapGuesture使用下面的代碼來獲取部分指數

- (void)handleTapGuesture:(UITapGestureRecognizer *)gesture { 
    int section = (int)gesture.view.tag; 
}