开发者

detect UITableViewCell id on UIImageView

I have a UITableView. I place an UIImageView on each row UITableViewCell. I used the codes below to detect 开发者_JS百科the touch on the UIImageViews

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


}

It looks like I can only get the pt, Is it possbile to detect which row's UIImageView is touched?

Thanks

interdev


Yes, it is possible (UITableView has a method allowing to what row specific point belongs to):

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


In tableView:cellForRowAtIndexPath: you could set the imageview's tag property to the current row index. Then just read the tag off the imageview to see which row it's in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜