2013-03-01 45 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