我已经有UITableView
已经编程创建。我现在试图添加使用编辑模式删除行的功能。iOS“刷卡删除”不改变编辑按钮状态
我添加了这样的默认方式:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
当你轻点按钮,进入编辑模式,按钮变为“完成”按钮。
但是,当我“滑动删除”行时,只显示删除按钮,现有编辑按钮不会更改为“完成”。
有什么我需要做额外的,因为我以编程方式创建表视图?
下面是我的实现代码如下代码:
- (void)viewDidLoad
{
self.voucherTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 36, 320, self.view.frame.size.height - 36) style:UITableViewStylePlain];
self.voucherTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.voucherTableView.delegate = self;
self.voucherTableView.dataSource = self;
[self.view addSubview:self.voucherTableView];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
// Default table view data source methods go here
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[self.voucherTableView setEditing:editing animated:animated];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Commit the delete
}
}
我对你的问题有点困惑。通常使用左侧的删除按钮或通过滑动/滑动删除来完成删除。无论哪种情况,你都应该得到一个“删除”按钮来确认。 “完成”按钮与删除无关,只是退出编辑模式。查看tableview的完整设置也很有帮助。 –
感谢您的评论。对于这两种类型的编辑,我都得到了“删除”按钮,但是当您执行“幻灯片删除”时,原始的“编辑”按钮不会更改为“完成”。我已将我的代码添加到原始问题中。 –
好多了! –