Ios UICollectionViewCell按钮单击并更改单元格上的文本

Ios UICollectionViewCell按钮单击并更改单元格上的文本,ios,uibutton,uicollectionviewcell,Ios,Uibutton,Uicollectionviewcell,我想在单击按钮时更改按钮(UIButton位于UICollectionViewCell内)文本。我怎么才能拿到手机和按钮?我有一个定制的手机 [cell.shareButton addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside]; -(void)shareAction:(UIButton*)button { NSIndexPath *indexPat

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

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
}

“单元格”和“按钮”变量是按下的按钮,它是单元格。

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

+1 button.superView获取单元格的contentView,它的superView是UICollectionViewCell。+1 button.superView获取单元格的contentView,它的superView是UICollectionViewCell。