2012-07-26 109 views
3

我的概念在UITableView中刪除行有一個小問題。用戶刪除一行後,我不想觸發:UITableView commitEditingStyle不刪除單元格

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; 

相反,我想更改編輯的單元格文本和背景,而不隱藏它。我的方法工作得很好:

if (editingStyle == UITableViewCellEditingStyleDelete) { 
    NSMutableArray *previous_points = [self.trip_arrayOfAllPoints mutableCopy]; 
    [previous_points removeObjectAtIndex:indexPath.row]; 
    self.trip_arrayOfAllPoints = nil; 

    self.trip_arrayOfAllPoints = [[NSMutableArray alloc] initWithCapacity:[previous_points count]]; 
    self.trip_arrayOfAllPoints = [previous_points mutableCopy]; 

    self.trip_arrayOfAllPointsEDITED = [[NSMutableArray alloc] initWithCapacity:[previous_points count]]; 
    self.trip_arrayOfAllPointsEDITED = [previous_points mutableCopy]; 
    //[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; 

    self.trip_isArrayOfAllPointsEDITED = YES; 
} 

但刪除行並不承擔dissapearing的動畫完成後,「刪除」標籤上當前單元格。是否有解決刪除行的「Apple方式」?

編輯 - 我已經工作了

這是非常簡單樸素。只需更換與deleteRowsAtIndexPaths:

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 

在此之後「刪除」的動畫會消失,細胞仍然是在它的地方。

回答

2

你的意思是「刪除」按鈕的客人,即使你按下了嗎?在 後,我的的iOS 5.1模擬器按 「刪除」 空:

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

「刪除」 按鈕消失。

+0

將此方法留空並查看按刪除時發生的情況。簡單地/ *在開頭和* /在結尾。 – solgar 2012-07-26 09:23:22

+1

謝謝你,在我發佈信息之後,我決定將方法留空並用我的細胞進行操作。這解決了我的問題(這太簡單了:))。 – 2012-07-26 09:26:38

1

我使用此代碼,它的正常工作

//self.selectedMessageIndex is NSIndexPath object declared in header file 
//self.attachments is a NSMutableArray Object 

[self.attachments removeObjectAtIndex:self.selectedMessageIndex.row]; 

[tblvAttachmentsList deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.selectedMessageIndex] 
            withRowAnimation:UITableViewRowAnimationLeft]; 
[tblvAttachmentsList reloadData]; 
+1

我真的不想提交刪除動畫。我只想排隊留在原地,但有不同的顏色/背景等。這是問題所在。 – 2012-07-26 09:20:20

+0

所以你解決了它 – 2012-07-26 09:26:56

+0

我們真的需要在這裏使用「reloadData」嗎?我認爲沒有必要。 – 2015-06-19 07:43:42

0
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation:.Automatic) 

這將刪除一個漂亮的動畫刪除按鈕。調用時,當你知道你不會刪除該行時:

func tableView(tableView: UITableView, commitEditingStyle editingStyle:UITableViewCellEditingStyle, forRowAtIndexPath indexPath:NSIndexPath) { 
    if (editingStyle == UITableViewCellEditingStyle.Delete) { 

     //An action happens here. If it was successful, page is refreshed 
     //If the action fails, cell stays. I am showing an error and: 
     self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation:.Automatic) 
    } 
} 
相關問題