1

UIButtonボタンをクリックしたときにボタン ( is inside 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
}

「セル」変数と「ボタン」変数は押されたボタンであり、セルです。

于 2013-04-21T08:02:38.033 に答える