2013-03-01 35 views
0

我使用下面的代碼來顯示刪除按鈕時,用戶滑動tableview單元格。我想在這個按鈕中寫取消而不是刪除,我怎樣才能實現這個功能?Swipe to取代而不是刪除UITableView

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

而且

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
    //remove the deleted object from your data source. 
    //If you're data source is an NSMutableArray, do this 
    [self.dataArray removeObjectAtIndex:indexPath.row]; 
    } 
} 
+0

可能重複(http://stackoverflow.com/questions/1615469/custom-delete-button-on-editing-in-uitableview-cell) – dasblinkenlight 2013-03-01 15:24:47

+0

它似乎你想保持功能,但顯示一個不同的按鈕。在這種情況下,滾動到最高票數的答案,看看你怎麼能做到你想要的。 – dasblinkenlight 2013-03-01 15:25:37

回答

2

如果你想要做的是改變了按鈕設置爲「取消」的稱號,那麼就實現你的表視圖的委託-tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:方法。

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return @"Cancel"; 
} 
的[在UITableView的細胞自定義刪除按鈕開編輯]
+0

It Worksss .. :)謝謝@macserv – 2013-03-01 15:31:51