我想处理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:]:无法识别的选择器已发送到实例0x9c75e40
最佳答案
您应该实现UICollectionViewDelegate protocol并找到方法:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
告诉您用户何时触摸一个单元格