我有一个视图,它有自己的导航栏和一个tableview。我想编辑&删除该表视图中的项目。我在这样的导航栏上放置并编辑了按钮。

self.navItem.leftBarButtonItem = self.editButtonItem;

还有一个像这样的方法。

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if(editingStyle == UITableViewCellEditingStyleDelete) {

        //Get the object to delete from the array.
        //Delete the object from the table.
        [self.tblView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

但是当我点击该按钮时,tableview中的任何项目都不会显示该红色标记图标。只需编辑按钮的标题更改为“完成”。

应该是什么问题?

有帮助吗?

解决方案

这是UIViewController还是UITableViewController?它将出现(来自附加代码中的self.tblView)您正在使用标准的UIViewController。在这种情况下,您必须在视图控制器中实现setEditing:animated:,而后者应该在表视图中调用它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top