当我点击按钮时,我想更改按钮(UIButton
在UICollectionViewCell
内)文本。如何获取单元格和按钮?我有一个自定义单元格。
[cell.shareButton addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
-(void)shareAction:(UIButton*)button {
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint: [self.collectionView convertPoint:button.center fromView:button.superview]];
NSLog(@"row %d",indexPath.row);
NSLog(@"section %d",indexPath.section);
}
答案 0 :(得分:1)
UIButton是发件人:
- (void)shareAction:(UIButton *)button {
// the 'button' parameter is your required button.
// now let's get the cell
UICollectionViewCell *cell = button.superview.superview.
// this is the cell
}
'cell'和'button'变量是按下的按钮,它是单元格。