我想要處理攻絲UICollectionView單元格。嘗試用下面的代碼來實現這一目標:如何將事件添加到UICollectionView單元格?
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cvCell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
// Some code to initialize the cell
[cell addTarget:self action:@selector(showUserPopover:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)showUserPopover:(id)sender
{
//...
}
但在該行[cell addTarget:...]
與下面的錯誤執行遊:
-[UICollectionViewCell addTarget:action:forControlEvents:]: unrecognized selector sent to instance 0x9c75e40
這隻能如果觸摸事件適用於整個小區的迅速4。 –