UItableview 中的图像
嘿 我有一个基本的表格视图,其中包含图像和文本。当点击一个单元格时,我希望发生一些特定的事情,无论是触摸图像还是单元格的其余部分。有没有办法找出细胞的哪一部分被触摸了 谢谢
Hey
I have a basic table view with an image and text in it. When a cell is tapped I would like something specific to happen whether the image is touched or the rest of the cell. Is there a way to find out what part of the cell has been touched
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 UITapGestureRecognizer 添加到您的 imageView,或将 imageView 更改为以图像作为背景的自定义 UIButton。
您可以将它们连接到您自己的方法,我们将其称为
imageTapped:
。您将得到如下所示的选定索引路径:根据单元格布局,必须调整获取索引路径的方式。
Add a UITapGestureRecognizer to your imageView, or change the imageView into a custom UIButton that has an image as background.
You would connect them both to your own method, lets call it
imageTapped:
. And you would get the selected indexpath like this:depending on the cell layout the way to get the indexpath has to be adapted.
你为什么不尝试这样的事情
当用户点击一次这个方法将被调用,这样你就可以通过设置 imageView = indexPath.row 的标签或你选择的任何东西来跟踪哪个图像被点击。
why dont you try somthing like this
When ever user tap once this method will be called so you can keep track of which image is tapped by setting tha tag of imageView = indexPath.row Or any thing of your choice.