1

我正在开发一个类似于 Apple 提醒应用程序的应用程序。我有一个带有数据的 tableView。该单元格具有 UIImageView 和 Disclosure Indicator 附件视图。当它的任何一行被选中时,就会推送一个视图控制器。

我希望每行的 UIImageView 与行选择分开工作,就像在 Apple 提醒应用程序中一样。我怎样才能做到这一点?

我已经尝试将 UIimageview 作为单元格的子视图,并将 UITapGestureRecognizer 添加到其中。它适用于最后插入的行,但不适用于其他行。

4

2 回答 2

1

与其继承 UIImageView,不如考虑继承 UITableViewCell。在您的子类中,您仍然可以将 UITapGestureRecognizer 添加到 UIImageView,但您将针对您的单元格子类的方法(而不是您的表控制器,尽管您没有说明处理程序当前的目标是什么)。

将一个 tapRecognizer 添加到您的自定义单元格的 UIImageView,并在您的自定义单元格上添加一个 BOOL 标志(例如,imageViewTapped)。在您的点击处理程序中,将 imageViewTapped 设置为 YES。

现在,无论点击是否在 imageVIew 上,您的 tableView 控制器仍将调用 didSelectRowWithIndexPath。因此,在 didSelectRowAtIndexPath 中,评估自定义单元格的 imageViewTapped 属性。如果已设置标志,则将 viewController A(用于 imageView 行为)推送到导航堆栈上。如果 imageViewTapped == NO,推送 viewController B(大概是你已经过渡到的)。

于 2013-02-06T01:00:53.863 回答
1

@阿德尔。您可以在 imageView 上放置一个透明按钮以响应用户的触摸。

CGRect imageRect = (CGRect){100, 100, 100, 100};
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:imageRect] autorelease];
imageView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:imageView];
imageView.userInteractionEnabled = YES;

UIButton *maskBtn = [UIButton buttonWithType:UIButtonTypeCustom];
maskBtn.frame = imageView.bounds;
maskBtn.backgroundColor = [UIColor clearColor];
[maskBtn addTarget:self action:@selector(maskBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:maskBtn];

注意 imageView 的 userInteractionEnabled 默认为 NO。希望有所帮助。:)

于 2013-02-06T02:09:10.987 回答