gpt4 book ai didi

ios - 将上下文信息与点击手势相关联

转载 作者:行者123 更新时间:2023-11-28 22:26:34 25 4
gpt4 key购买 nike

我有一个 UITableView,每行有两个图像。这些图像来自数据结构。我想设置一个点击事件并让点击事件处理程序根据所选图像检索数据结构。有没有办法关联上下文数据?

或者我是否必须维护将 uiimage 映射到我的数据的映射?

我也不希望每个图像都有一个单独的处理程序。

最佳答案

通过使用点击手势,您可以实现类似的功能:

- (void)didRecognizeTapGesture:(UITapGestureRecognizer*)gesture
{
if (gesture.state == UIGestureRecognizerStateEnded)
{
CGPoint point = [gesture locationInView:self.tableView];

NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];

if (indexPath != nil)
{
MyCustomCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

point = [self.tableView convertPoint:point toView:cell];

if (CGRectContainsPoint(cell.imageView1.frame, point))
{
//it touches image 1
}
else if (CGRectContainsPoint(cell.imageView2.frame, point))
{
//it touches images 2
}
}
}

}

关于ios - 将上下文信息与点击手势相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18795420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com