tags:

views:

22

answers:

2

Hello everyone

I have a UITableView. I place an UIImageView on each row UITableViewCell. I used the codes below to detect 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

A: 

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];
}
Vladimir
Thanks. But it looks like only worked when I touch the part outside UITableView. Do I need to set any protocol between touch any UITableView?
sorry, can't see the problem...In what class are you tracking touches? And do you really need to use UIIMageView? May be you can use UIButton with background image - it will be easier to handle events on it
Vladimir
A: 

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.

Brian