2011-02-23 33 views
0

嘿 我有一个基本的表格视图,里面有图像和文字。当点击一个单元格时,我希望特定的事情发生在图像是否被触摸或单元格的其余部分。有没有办法找出已经触摸过什么部分的细胞 谢谢UItableview中的图像

回答

0

将UITapGestureRecognizer添加到imageView,或将imageView更改为以图像为背景的自定义UIButton。
你可以将它们连接到你自己的方法,我们可以称它为imageTapped:。你会得到选择indexpath这样的:

- (IBAction)imageTapped:(id)sender { 
    UIView *cellContentView = [sender superview]; 
    UITableViewCell *cell = (UITableViewCell *)[cellContentView superview]; 
    NSIndexPath *tappedIndexPath = [tableView indexPathForCell:cell]; 
    // do something 
} 

取决于电池的布局,以获得indexpath的方式必须适应。

+0

当我尝试时,这没有奏效。任何其他方式? – user591375 2011-02-23 09:03:04

0

你为什么不尝试财产以后这样

UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(someMethodName)]; 
    tapGesture.numberOfTapsRequired = 1; 
    UIImageView* myImageView = [[UIImageView alloc] initWithFrame:CGRectZero]; 
    [myImageView addGestureRecognizer:tapGesture]; 

当过自来水用户一旦这个方法会被调用,所以你可以跟踪哪些图像是通过设置的ImageView的THA标签= indexPath.row或任何窃听你选择的东西。

+0

“initWithFrame:CGRectZero”它只是例如你可以随心所欲。只需添加一个TapGesture吧 – 2011-02-23 09:26:08

+0

这意味着我需要一个自定义单元格来拥有UIImageView。我要使用UITableView单元格的默认图像 – user591375 2011-02-23 17:57:46