2011-05-30 39 views
0

我使用touchesBegan:withEvent:獲取用戶在屏幕上的觸摸,但是當我觸摸tableView中的單元格時,此方法沒有得到我給view.and的標籤,並且x和y來自單元格,而不是來自全屏。touchBegan in TableView

-(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; 

} 

這是touchesBegan:withEvent:方法。有什麼方法可以解決它?

回答

0

你應該使用這種方法:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 

這是一個委託方法,所以不要忘記你的委託和數據源連接在Interface Builder。

Apple Documentation - UITableViewDelegate

+0

我想要得到的x和這是在屏幕觸及Y和我可以讓他們當我用這個方法 – yosifz8 2011-05-30 17:33:40

+0

好了...所以你需要使用convertPoint方法,例如:[self convertPoint:finger toView:[UIScreen mainScreen]]; – jlink 2011-05-30 17:38:21

+0

我不能使用,因爲它返回uiscreen而不是UIView:[UIScreen mainScreen] – yosifz8 2011-05-30 21:43:02

相關問題