ios - 在 UITableView 中滑动取消而不是删除

标签 ios cocoa-touch

我使用以下代码在用户滑动 tableview 单元格时显示删除按钮。我想在这个按钮中写取消而不是删除,我怎样才能实现这个功能??

- (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];
  }
}

最佳答案

如果您只想将按钮的标题更改为“取消”,则只需在 TableView 的委托(delegate)中实现 -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: 方法即可。

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"Cancel";
}

关于ios - 在 UITableView 中滑动取消而不是删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15161103/

相关文章:

ios - 如何根据 Childviewcontroller(UIViewController 的不同大小)高度更改容器 View (父 View )的高度?

ios - 如何删除Xcode项目文件?

ios - 如何查看用户使用的 iOS 设备?

ios - 在 AppDelegate 中实例化 UINavigationController

objective-c - UITextField "value changed"字段更新时未触发

ios - 如何在多个 View 中重用相同的 UIButton

ios - 手动添加要查看的项目后无法滚动到 UIScrollView 的底部

ios - 检查哪个委托(delegate)插入模态视图 Controller 的优雅解决方案是什么?

iphone - 如何在 iPhone 上将中文文本音译为拼音?

iphone - 如何在UITableView下面添加UIButton?