2013-03-18 61 views
0

我有一個UITableview,我把它放在一個JASidePanel控制器(https://github.com/gotosleep/JASidePanels)我已經在我的init方法中設置了委託和數據源,並且我已經實現了canEditRowAtIndexPath方法,並且在我滑動時正在調用它們在tableview單元格上,但沒有任何事情發生。我查看了其他問題,並已實施所有建議,但無法顯示刪除按鈕。有誰知道什麼會導致這種行爲?UITableViewCell刪除按鈕不出現

回答

7

您必須實施tableView:editingStyleForRowAtIndexPath:委託方法和tableView:commitEditingStyle:forRowAtIndexPath:數據源方法。沒有這些,刪除將不會出現在單元格中。

我假設您從tableView:canEditRowAtIndexPath:數據源方法(至少對於相應的行)返回YES

+0

我終於明白了這一點。我選擇了這個答案,因爲所有你需要做的就是實現這兩個方法,它的工作原理。我已經實現了這兩種方法,但刪除按鈕被隱藏在JASidePanel的中心面板控制器下面...我只需要縮小tableview的寬度就可以了。 – AFraser 2013-03-18 15:05:42

+0

@AFraser - 實際上,您的評論幫助我回答了我的問題自己的問題,因爲我的問題非常相似(主視圖(在自定義拆分視圖控制器中)的右側被詳細視圖遮擋)。我肯定會建議把它作爲答案,因爲你的問題確實提到了JASidePanel控制器。 – Animal451 2014-02-05 08:21:19

1

您是否嘗試過使用此類自己的刪除單元格的方法?

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (UITableViewCellEditingStyleDelete) { 
     int k = [[tempArray objectAtIndex:indexPath.row] intValue]; 

     //Remove object from index 'k'. 
    } 
} 

它可能會幫助你。

謝謝。

0

在刷新TableViewCell時對UITableView執行刪除操作。我們必須執行以下三種方法: -

此方法將在滑動TableViewCell時顯示刪除按鈕。

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
     editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSUInteger row = [indexPath row]; 
    NSUInteger count = [posts count]; 

    if (row < count) { 
    return UITableViewCellEditingStyleDelete; 
    } else { 
    return UITableViewCellEditingStyleNone; 
    } 
} 

當用戶刪除TableViewCell的刷卡及刷行的行這種方法被稱爲將在敲擊按鈕,刪除被刪除。

- (void)tableView:(UITableView *)tableView 
     commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
     forRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSUInteger row = [indexPath row]; 
    NSUInteger count = [posts count]; 

    if (row < count) { 
    [posts removeObjectAtIndex:row]; 
    } 
} 

最後調用此方法在刪除行後更新表視圖。

- (void)tableView:(UITableView *)tableView 
        didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { 

    [self updateViewTitle]; 
    [tableView reloadData]; 
}