uitableview - 使用 UIViewController 创建的 UITableView 中的编辑功能

标签 uitableview

我使用 UIViewController(而不是 UITableViewController)创建了表,并将 UITableView 作为其属性。
我已经实现了 DataSource 和 Delegate 协议(protocol)的必要方法。但是当我单击编辑按钮时,我看不到其单元格的任何删除(红色减号),因此我可以选择它们进行删除。
如果我使用 UITableViewController,同样可以正常工作。我已经实现了以下方法。

我错过了什么,它在使用标准 UITableViewController 时的行为方式不一样?

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
self.navigationItem.rightBarButtonItem.enabled = !editing;
}


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

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView     editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

最佳答案

需要切换UITableView到编辑状态:

[self.tableView setEditing:YES animated:YES];

关于uitableview - 使用 UIViewController 创建的 UITableView 中的编辑功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12496841/

相关文章:

ios - 当从 contentSize 给出 tableview 高度时,不调用 cellForRowAt indexPath

ios - 这个过滤器与 ios 中侧边栏的联系人名称是什么?

ios - UITableView - UITableViewCell.Style .subtitle - 如何使 UIImageView 圆形? - swift 5

ios - 在单元格出列并重新加载之前,tableviewcell 中的属性字符串不显示粗体文本

ios - 如何仅引用indexPathsForVisibleRows中的第一个对象

ios - 刷新 TableView iphone

ios - 为什么我不能更改 UIButton 文本颜色?

ios - 用 Facebook 好友填充 UITableView

ios - UITableViewCell textLabel.text 未显示在单行中

swift - 表格 View 和日期选择器之间的空白