单元格内的UIButton以编程方式

时间:2015-10-25 18:10:03

标签: ios objective-c uicollectionview

当我将UIButton放在UICollectionView的单元类中时,谁是目标?我无法将目标设置为" self",但它必须是父集合视图,其中我没有指向单元格类的指针..

//inside a cell class (`uicollectionviewcell`)


  [self.deleteCell addTarget:self action:@selector(clearCell:)forControlEvents:UIControlEventTouchUpInside];

应该是什么而不是self

1 个答案:

答案 0 :(得分:2)

在此方法中自行添加目标:

   - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

我使用cell.button进入该按钮,并将目标添加到self(这是集合)