2010-08-03 38 views
0

我有一個UITableView。 我在每行UITableViewCell上放置一個UIImageView。 我用下面的代碼來檢測上的UIImageViews檢測UIImageView上的UITableViewCell id

-(void) touchBegan:(NSSet*) touches withEven:(UIEvent*)event 
{ 
CGPoint pt=[[touches anyObject] locationInView:self]; 


} 

它看起來像我只能得到PT觸摸, 是否possbile檢測的UIImageView被觸摸哪一行的?

感謝

InterDev中

回答

0

是的,這是可能的(UITableView中有允許的方法是什麼行特定點屬於):

-(void) touchBegan:(NSSet*) touches withEven:(UIEvent*)event 
{ 
    CGPoint pt=[[touches anyObject] locationInView:self]; 
    CGPoint pointInTable = [[touches anyObject] locationInView:yourTableView]; 
    NSIndexPath* path = [yourTableView indexPathForRowAtPoint:pointInTable]; 
} 
+0

謝謝。但它看起來只在我觸摸UITableView外的部分時才起作用。我需要在觸摸任何UITableView之間設置任何協議嗎? – arachide 2010-08-03 09:36:17

+0

對不起,看不到問題...在跟蹤觸摸什麼課?你真的需要使用UIIMageView嗎?也許你可以在背景圖像上使用UIButton - 處理事件會更容易 – Vladimir 2010-08-03 15:41:21

0

tableView:cellForRowAtIndexPath:你可以設置的ImageView標記屬性到當前行索引。然後,只需從im​​ageview中讀取標籤即可查看它所在的行。

相關問題