UItableview 中的图像

发布于 2024-10-19 07:13:46 字数 93 浏览 2 评论 0原文

嘿 我有一个基本的表格视图,其中包含图像和文本。当点击一个单元格时,我希望发生一些特定的事情,无论是触摸图像还是单元格的其余部分。有没有办法找出细胞的哪一部分被触摸了 谢谢

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷→糖丶微凉 2024-10-26 07:13:46

将 UITapGestureRecognizer 添加到您的 imageView,或将 imageView 更改为以图像作为背景的自定义 UIButton。
您可以将它们连接到您自己的方法,我们将其称为 imageTapped:。您将得到如下所示的选定索引路径:

- (IBAction)imageTapped:(id)sender {
    UIView *cellContentView = [sender superview];
    UITableViewCell *cell = (UITableViewCell *)[cellContentView superview];
    NSIndexPath *tappedIndexPath = [tableView indexPathForCell:cell];
    // do something
}

根据单元格布局,必须调整获取索引路径的方式。

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:

- (IBAction)imageTapped:(id)sender {
    UIView *cellContentView = [sender superview];
    UITableViewCell *cell = (UITableViewCell *)[cellContentView superview];
    NSIndexPath *tappedIndexPath = [tableView indexPathForCell:cell];
    // do something
}

depending on the cell layout the way to get the indexpath has to be adapted.

去了角落 2024-10-26 07:13:46

你为什么不尝试这样的事情

    UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(someMethodName)];
    tapGesture.numberOfTapsRequired = 1;
    UIImageView* myImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [myImageView addGestureRecognizer:tapGesture];

当用户点击一次这个方法将被调用,这样你就可以通过设置 imageView = indexPath.row 的标签或你选择的任何东西来跟踪哪个图像被点击。

why dont you try somthing like this

    UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(someMethodName)];
    tapGesture.numberOfTapsRequired = 1;
    UIImageView* myImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [myImageView addGestureRecognizer:tapGesture];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文