UIimageView 和辅助视图在 TableViewCell 中分开工作 [英] UIimageView and Acessory View to work separately in TableViewCell

查看:27
本文介绍了UIimageView 和辅助视图在 TableViewCell 中分开工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on on an app similar to Apple reminders app. I have a tableView with data. The cell has an UIImageView and Disclosure Indicator accessory view. When any of its row is selected, a view controller is pushed.

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

I would like for the UIImageView of each row to work separately from the row selection as it is in Apple reminders app. How can I do that?

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

I have tried UIimageview as subview for the cell and added UITapGestureRecognizer to it. It worked fine with last inserted row but did not with other rows.

推荐答案

@Adel.您可以在 imageView 上放置一个透明按钮来响应用户的触摸.

@Adel. You can put a transparent button on the imageView to respond to user's touch.

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.希望有所帮助.:)

Notice that imageView's userInteractionEnabled is NO by default. Hope helps. :)

这篇关于UIimageView 和辅助视图在 TableViewCell 中分开工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆