开发者

detect UITableViewCell id on UIImageView

开发者 https://www.devze.com 2023-01-10 04:22 出处:网络
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

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

精彩评论

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