在我的tableView小区i有:如何检测用户是否直接点击cell.imageView而不是在tableview单元格中的标签上?
cell.imageView.image = image;
我怎么能直接检测到图像上的用户点击,而不是cell.textLabel?
在我的tableView小区i有:如何检测用户是否直接点击cell.imageView而不是在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);
}
很酷的解决方案:)。奇迹般有效。 – joey 2011-06-02 17:13:24
正如一些评论指出的那样,您应该改用UIButton
。 A UIImageView
不适用于处理用户交互操作,只需创建按钮,添加目标并将其添加为单元格的子视图就简单多了。
改用UIButton .. – Jhaliya 2011-06-02 15:13:22
'UIButton'正常工作! – 2011-06-02 15:18:54