ios - UITableViewCell,在滑动时显示删除按钮

如何在 UITableViewCell 上滑动时显示删除按钮?该事件永远不会引发,删除按钮也永远不会出现。

最佳答案

(-viewDidLoad 或storyboard)中启动时做:

self.tableView.allowsMultipleSelectionDuringEditing = false

覆盖以支持表格 View 的条件编辑。仅当您要为某些项目返回 NO 时,才需要执行此操作。默认情况下,所有项目都是可编辑的。

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete
    }    
}

https://stackoverflow.com/questions/3309484/

相关文章:

ios - 在 ARC 下,IBOutlets 应该强还是弱?

ios - 如何以编程方式在 iPhone 上发送短信?

objective-c - @synthesize 与 @dynamic,有什么区别?

objective-c - 如何在 Xcode 4 中设置 NSZombieEnabled?

objective-c - 在 Objective-C 中创建一个抽象类

ios - 设置 UITextField 的最大字符长度

ios - 如何以编程方式创建基本的 UIButton?

ios - 如何浏览文本字段(下一步/完成按钮)

ios - UITextField 文本更改事件

objective-c - 在 Objective-C 中,我如何测试对象类型?