0

我有一个基于核心数据/ uitableview 的应用程序。实际上,到目前为止 80% 的代码与 Apple 示例应用程序 CoreDataRecipes 相同。我的问题是,当我进入编辑模式(通过按下编辑按钮)时,行的左侧没有“删除徽章”。保险杠。

替代文字

与 CoreDataRecipes 的代码差异:

  1. 我有一个带有 nib 文件的自定义 UITabelview 单元格,而不仅仅是代码。
  2. 我的 Tableview 是我班级视图中的一个插座。所以我的类 RecipeListTableViewController 是一个带有 Tableview 委托的 UIViewController 而不是 UITableViewController

我尝试了什么:

  • 表视图工作正常。没有链接或委托问题
  • 我检查了表格是否真的进入了编辑模式。确实如此。您可以看到,因为“添加”按钮被禁用。
  • 我检查了编辑风格是否正常。它应该是默认的,但要确保我添加了:

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

  • 我检查了删除图标是否不在我的单元格视图后面。没有。我现在认为向右移动的单元格行为是由 iOS 处理的。

  • 当我滑动单元格时,右侧的删除按钮会出现并正常工作
  • 我试图用 layoutSubviews 来构建我自己的行为。进入编辑模式时没有任何变化。但是当我滑动时,现在我在一行中看到我的子视图:

替代文字

有人有什么想法吗?它一定很简单。

4

4 回答 4

3

确保

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{

    return YES;
}

如果这未设置为返回 YES,则不会启用徽章。默认设置为返回 NO

于 2013-05-16T09:12:16.763 回答
1

我认为您没有 tableView.editing=YES 在单击“编辑”按钮时添加该行

通过设置尝试!

于 2011-01-12T08:30:54.460 回答
1

由于你的是 UIViewController,tableview 没有得到 setEditing 调用。只需添加:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.tv setEditing:editing animated:YES];
}
于 2011-08-15T06:42:57.877 回答
0

确保你已经设置了出口/委托/数据源然后这些:

-(void)editButtonTapped
{
    [self.tableView setEditing:YES animated:YES];
}



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

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
于 2015-09-02T05:24:30.437 回答