1

单击按钮时,我想更改按钮(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);
}
4

1 回答 1

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' 变量是按下的按钮,它是单元格。

于 2013-04-21T08:02:38.033 回答