2013-04-21 164 views
1

我想單擊按鈕時更改按鈕(UIButtonUICollectionViewCell內)文本。我如何獲得單元格和按鈕?我有一個自定義單元格。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); 
} 

回答

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 
} 

的 '細胞' 和 '按鈕' 的變量是被按下的按鈕,並且它的細胞。

+0

+1 button.superView獲取單元格的contentView,它的superView是UICollectionViewCell。 – Anupdas 2013-04-21 08:46:28

相關問題