2012-05-05 50 views
4

我有第二個確認對話框,當用戶決定刪除一個UITableViewCell時出現。這是在正常狀態下我的表視圖:恢復UITableViewCell到正常編輯模式

Normal


而且這裏的時候,整個表進入編輯模式,它是:

Normal editing mode


現在,當用戶點擊左側的紅色減號之一,該單元進入刪除確認模式:

Delete confirmation mode


然後,如果用戶敲擊刪除按鈕是剛剛出現,顯示此動作片:

Second confirmation


這是哪裏出了問題就出現了。如果用戶確認他們想要刪除地圖,一切都很好。但是,如果取消按鈕被按下,動作片消失,但表視圖仍然是這樣的:

The delete confirmation button should no longer be in its selected state, and should have hidden itself from view

的問題是,刪除確認按鈕應該不再處於選中狀態,並應從視野中隱藏起來。正如你可以看到它沒有。我在文檔中的搜索結果沒有結果。我不想setEditing:NO,因爲我希望表格保持其正常編輯狀態。有任何想法嗎?

編輯1:這裏是那張裏面tableView:commitEditingStyle:forRowAtIndexPath:

- (void)tableView:(UITableView*)tableView commitEditingStyle: 
    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath { 
    NSInteger finalIndex = [self getFinalIndexForIndexPath:indexPath]; 

    NSString* mapTitle = ((PreviewDataObject*)[[[SingletonDataController sharedSingleton] 
     getImportedOrSavedMapPreviews:masterIdentifierString] 
     objectAtIndex:finalIndex]).titleString; 

    UIActionSheetWithIndexPath* sheet = [[UIActionSheetWithIndexPath alloc] initWithTitle: 
     [NSString stringWithFormat:@"Are you sure you want to delete the map '%@'?", 
     mapTitle] delegate:self cancelButtonTitle:@"Cancel" 
     destructiveButtonTitle:@"Delete Map" otherButtonTitles:nil]; 
    sheet.indexPath = indexPath; 
    [sheet showFromTabBar:[AppDelegate appDelegate].tabBarController.tabBar]; 
    [sheet release]; 
} 
+0

可以u顯示的代碼 - (空)的tableView:(UITableView的*)的tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath :(NSIndexPath *)indexPath –

+0

你能告訴我們你在這裏的數組名稱是什麼? – vishiphone

+0

在'commitEditingStyle'中,我實際上並沒有做任何刪除;我只是提出了提示用戶是否真的要刪除地圖的操作表。 –

回答

1

之後,你可能會提出一個AlertView詢問他們是否確實真的想要刪除。

打開按鈕,然後按刪除的兩個步驟應該是足夠的確認。

做你在做什麼在我看來並不是標準的做法,一旦你進入那個領域,你會在框架中找到漏洞。

+0

我想你可能是對的,但我仍然希望有辦法做我想做的事。 –

+0

我認爲@ eric.mitchell試圖完成的是合理的。儘管如此,這個答案讓我真的很開心:)。有一個簡單的方法來完成你所問的,請看我的答案。 4年後雖然... – oyalhi

0

剛剛嘗試這一點,並告訴我,它爲你工作或沒有。

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     if (editingStyle == UITableViewCellEditingStyleDelete) 
     { 
      // Delete the row from the data source. 

      [arr removeObjectAtIndex:indexPath.row]; 


      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     } 
     else if (editingStyle == UITableViewCellEditingStyleInsert) 
     { 
      // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
     } 
    } 
1

我同意上面的討論,需要刪除3次是一個壞主意。

但是,對於其他操作,可能有重置行的一個很好的理由。最簡單的解決方案就是重新加載一行。

Swift 2。2:

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

簡單地退出編輯模式(SWIFT):

tableView.setEditing(false, animated: true) 
相關問題