在我的 tableView 单元格中我有:
cell.imageView.image = image;
如何检测用户是否直接点击了该图像,而不是 cell.textLabel?
最佳答案
将 UITapGestureRecognizer 添加到 imageView。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
/* ... */
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.imageView.image = /*...*/
UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)] autorelease];
[cell.imageView addGestureRecognizer:tapGesture];
cell.imageView.userInteractionEnabled = YES;
}
/* ... */
}
- (void)imageTapped:(UITapGestureRecognizer *)gesture {
UITableViewCell *cell = [[[gesture view] superview] superview];
NSIndexPath *tappedIndexPath = [self.tableView indexPathForCell:cell];
NSLog(@"Image Tap %@", tappedIndexPath);
}
关于iphone - 如何检测用户是否直接单击 cell.imageView 而不是 tableview 单元格中的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6216390/