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.
精彩评论