2010-03-10 79 views
3

我被要求創建一個自定義的UITableViewCell,其中包含多個可以點擊的區域。iPhone:自定義UITableViewCell具有響應點擊的多個區域?

這些地區不會有按鈕或任何圖形 - 他們將是無形的。 3種不同的方法將根據該小區的第三用戶輕敲即

稱爲|| decrementFooCount || viewFooDetails || incrementFooCount ||

細胞有需要在任何時候都可見它的幾個標籤 - 在fooName和fooCount。

我在想也許三個隱藏在單元格的UIButtons?

我還需要維護滑動刪除默認行爲。

回答

5

你可以繼承你的UITableViewCell並覆蓋touchesBegan:withEvent:方法。然後,您可以獲得觸摸位置的CGPoint。

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { 
    UITouch* touch = touches.anyObject; 
    CGPoint location = [touch locationInView:self]; 

    if (CGRectContainsPoint(myTestRect, location)) { 
     // Touched inside myTestRect, do whatever... 
    } else { 
     // Let the default implementation take over. 
     [super touchesBegan:touches withEvent:event]; 
    } 
} 

安德魯

+0

這看起來不錯。謝謝! – 2010-03-11 19:11:14

相關問題