代码之家  ›  专栏  ›  技术社区  ›  arachide

在UIImageView上检测UITableViewCell id

  •  0
  • arachide  · 技术社区  · 15 年前

    我有一个很好的视野。 我在每行UITableViewCell上放置一个UIImageView。 我使用下面的代码来检测UIImageViews上的触摸

    -(void) touchBegan:(NSSet*) touches withEven:(UIEvent*)event
    {
    CGPoint pt=[[touches anyObject] locationInView:self];
    
    
    }
    

    是否可以检测到触摸了哪一行的UIImageView?

    谢谢

    interdev公司

    2 回复  |  直到 15 年前
        1
  •  0
  •   Vladimir    15 年前

    是的,这是可能的(UITableView有一个方法允许指定行的点所属的位置):

    -(void) touchBegan:(NSSet*) touches withEven:(UIEvent*)event
    {
       CGPoint pt=[[touches anyObject] locationInView:self];
       CGPoint pointInTable = [[touches anyObject] locationInView:yourTableView];
       NSIndexPath* path = [yourTableView indexPathForRowAtPoint:pointInTable];
    }
    
        2
  •  0
  •   Brian    15 年前

    tableView:cellForRowAtIndexPath: 可以将imageview的tag属性设置为当前行索引。然后只需读取imageview上的标签,看看它在哪一行。