0

對於我的要求,我有一個UIScrollView下直接添加一個UITableView:的UITableView behin的UIScrollView

---主要的UIView

-------- UITableView的

----- --- UIScrollView

所以,當我滾動我的scrollview我改變了我的tableview的內容偏移量。它完美的作品。 但是,當我試圖選擇一個單元格,我不能趕上委託方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

有什麼特別的呢?我試圖子類的UIScrollView和實施:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

它的工作原理,但我不能滾動我的UIScrollView ...

+0

看起來你的滾動視圖捕捉所有觸摸事件,因爲它覆蓋了表視圖。 –

+0

是的,這就是爲什麼我想知道是否有辦法將觸摸事件傳輸到它下面的視圖中...... – Pete

+0

也許你應該將所有tap事件轉發到tableview並將所有其他觸摸事件保存到uiscrollview ,截至目前,你通過 - (void)touchesBegan監視所有表格視圖:(NSSet *)與事件觸發:(UIEvent *)事件。雖然這可以實施,審查你的邏輯。你在做什麼是不正確的。將有另一種方式來達到你想要的。 –

回答

2

試試這個,

-(void)handleSingleTap:(UILongPressGestureRecognizer *)gestureRecognizer{ 
    CGPoint p = [gestureRecognizer locationInView:myScroll]; 
    NSIndexPath *indexPath = [myTable indexPathForRowAtPoint:p]; 
    [myTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
    [self tableView:myTable didSelectRowAtIndexPath:indexPath]; 
} 

,你必須使用UITapGestureRecognizer ...

UITapGestureRecognizer *tpgr = [[UITapGestureRecognizer alloc] 
           initWithTarget:self action:@selector(handleSingleTap:)]; 
tpgr.numberOfTapsRequired = 1; 
[myScroll addGestureRecognizer:tpgr]; 
+0

這是很好的答案,我用這個鏈接完成:http://stackoverflow.com/questions/7667151/automatically-cell-selected-tableview。 selectRowAtIndexPath方法永遠不會調用tableView委託方法。 Thx爲您的提示:) – Pete

+0

是的我注意到,檢查我的編輯, – Aziz

+0

我不明白爲什麼你需要有一個代表你的手勢 – Pete