2011-02-04 67 views
1

這很奇怪。我正好在iPad模擬器中刷一個UITableViewCell。即使下面的事件觸發並且swipedCell不爲零,刪除按鈕也不會出現。實際上,它似乎 - 但只是有時。我從來沒有得到一個不好的訪問或sigbart。UITableViewCell刷卡,但沒有出現刪除按鈕

下面的代碼:

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer 
{ 
    if (userListSwipeRightRecognizer.state == UIGestureRecognizerStateEnded) { 
     CGPoint swipeLocation = [userListSwipeRightRecognizer locationInView:self.outletView]; 
     NSIndexPath *swipedIndexPath = [self.outletView indexPathForRowAtPoint:swipeLocation]; 
     UITableViewCell* swipedCell = [self.outletView cellForRowAtIndexPath:swipedIndexPath]; 
     [swipedCell setEditing:YES]; 

    } 
} 

這只是一個模擬器的問題還是我做錯了什麼?

+0

你有什麼理由爲什麼你自己處理滑動手勢,而不是讓UITableView自動執行它? – Costique 2011-02-04 18:59:19

+0

我將在單元格被刷過時在附件單元格中顯示「編輯」按鈕。我在做什麼可能不是最好的方法。這是我的第一個應用程序。 – Ali 2011-02-04 19:01:51

回答

0

如果你在頭文件中定義你的UITableView,然後嘗試:

swipedCell = [self.outletView cellForRowAtIndexPath:swipedIndexPath]; 
+0

我已經在OP代碼中這樣做了。你的意思是別的嗎?還是我誤解了你? – Ali 2011-02-04 19:04:34

10

如果你只是想使輕掃到刪除你的桌子上,有一個更簡單的方法來做到這一點。在你的數據源中實現tableView:commitEditingStyle:forRowAtIndexPath:,當一個單元格被滑動時,表格視圖將自動顯示刪除按鈕。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 
-1

如果使用自定義單元格並覆蓋setEditing,你必須調用超級方法或您刪除控件將無法繪製。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
} 
相關問題