touchBegan in a TableView
I use touchesBegan:withEvent: to get the touches of the user in the screen but when i touch a cell in a tableView this method didn't get the t开发者_如何转开发ag that i give the view.and the x and y are from the cell and not from the all screen.
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [[touches allObjects] objectAtIndex:0];
CGPoint finger = [touch locationInView:self];
int x = finger.x;
int y = finger.y;
}
This is the touchesBegan:withEvent:
method. there is any way to fix it?
You should use this method :
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
It is a delegate method, so don't forget to connect your delegate and datasource in Interface Builder .
Apple Documentation - UITableViewDelegate
精彩评论