2012-03-20 18 views
0

我有一個自定義的UITableViewCell,我在故事板中定義了它。我向表格單元格中的圖像添加了一個手勢。我抓住手勢就好,並改變圖像。當手勢觸發時獲取表單元格

我現在需要做的是從表格列表中刪除tableCell,但我無法找到對錶格單元格的引用。

如何獲取表格單元格indexPath或對錶格單元格的引用?我並不想在晚些時候爬上超級觀點,因爲在我看來,必須有一種更簡單/更好的方式。

謝謝。

回答

1

我實際上找到了一個解決方案。使用目標行動,我做到了。

-(void)checkMarkTapDetected:(id)sender { 
// Update the image 
UIImageView *checkMarkImage = (UIImageView *)[sender view]; 
checkMarkImage.image = [UIImage imageNamed:@"checkbox_checked.png"]; 

// Get recognizer and the place it fired in the tableview 
UIGestureRecognizer *gestureRecognizer = [[checkMarkImage gestureRecognizers] lastObject]; 
CGPoint location = [gestureRecognizer locationInView:self.tableView]; 

// Get table cell index based on gesture location in table view cell 
_checkMarkRowIndexPath = [self.tableView indexPathForRowAtPoint:location]; 
} 
+0

做得好,做得正確,不使用標籤! – jrturton 2012-03-21 18:26:22

+0

謝謝:)。我喜歡花時間思考更優雅的解決方案,而不是隻是抨擊那些可行但不具功能的東西。希望這有助於別人在未來。 – Michael 2012-03-27 21:12:59

0

我看到兩個選項。你可以使用deleteRowsAtIndexPaths:withRowAnimation:或者你可以發送reloadData到你的tableView。 reloadData會導致你的委託方法cellforRowAtIndexPath(和相關的方法)被再次調用,但這次你不會創建那個非常細胞。你的numberOfRowsInSection也必須反映行數的減少。

+0

我想你有點誤解了我的問題。這可能是我的措辭。我正在尋找單元格引用來實際調用表視圖的刪除方法。我真的想出了一個解決方案,並會發布一條新消息。 – Michael 2012-03-21 17:53:24

相關問題