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

时间:2013-04-21 07:52:05

标签: ios uibutton uicollectionviewcell

当我点击按钮时,我想更改按钮(UIButtonUICollectionViewCell内)文本。如何获取单元格和按钮?我有一个自定义单元格。

[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);
}

1 个答案:

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