简体   繁体   English

UITableview编辑模式下不显示左删除图标

[英]Left delete icons not appearing while UITableview edit mode

I have a core data/ uitableview based app. 我有一个基于核心数据/ uitableview的应用程序。 Actually 80% of the code so far is equal to the Apple Sample app CoreDataRecipes. 到目前为止,实际上80%的代码等于Apple Sample应用程序的CoreDataRecipes。 My problem is that when I enter the edit mode (by pushing the edit button), there are no "delete badges" on the left side of the rows. 我的问题是,当我进入编辑模式(按编辑按钮)时,在行的左侧没有“删除徽章”。 Bumper. 保险杠。

替代文字

The differences in code with CoreDataRecipes: CoreDataRecipes的代码差异:

  1. I have custom UITabelview cell with a nib file instead of code only. 我有一个自定义的UITabelview单元格,其中包含一个nib文件,而不是仅包含代码。
  2. My Tableview is an Outlet inside my class view. 我的Tableview是班级视图内的一个插座。 So my class RecipeListTableViewController is an UIViewController with Tableview delegates instead of a UITableViewController 所以我的类RecipeListTableViewController是带有Tableview委托的UIViewController而不是UITableViewController

What I tried: 我试过的

  • The Tableview works fine. Tableview工作正常。 There are no linking or delegate issues 没有链接或委托问题
  • I checked if the table actually enters the edit mode. 我检查了表格是否真正进入编辑模式。 It does. 是的 You can see that because the "Add" button is disabled. 您会看到,因为“添加”按钮被禁用。
  • I checked if the editingstyle is ok. 我检查了editstyle是否还可以。 It should be by default but to make sure I added: 它应该是默认设置,但要确保我添加了:

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

  • I checked if the delete icons where not behind my cellview. 我检查了删除图标是否不在cellview的后面。 There are not. 没有。 I now think that the cell behaviour of moving to the right is handled by iOS. 我现在认为,向右移动的单元格行为是由iOS处理的。

  • When I swipe the cell, the right delete button appears and works as it should 当我滑动单元格时,将出现右侧的删除按钮并按应有的方式工作
  • I tried to build the behaviour my self with a layoutSubviews. 我试图用layoutSubviews建立自己的行为。 Nothing changed when entering the edit mode. 进入编辑模式时,没有任何改变。 But when I swipe, now I see my subview in one row: 但是,当我滑动时,现在我在一行中看到了子视图:

替代文字

Anyone any ideas? 有任何想法吗? It must be something simple. 它一定很简单。

Make sure that 确保

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

    return YES;
}

If this is not set to return YES then the badges will not be enabled. 如果未将其设置为返回YES,则将不会启用徽章。 The default is set to return NO 默认设置为返回NO

I think you have not added the line tableView.editing=YES on clicking the Edit button 我认为您没有在单击“编辑”按钮时添加tableView.editing=YES

Try by setting it! 尝试设置它!

Since yours is a UIViewController, the tableview doesnt get the setEditing call. 由于您的是UIViewController,因此tableview不会获得setEditing调用。 Just add: 只需添加:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.tv setEditing:editing animated:YES];
}

Make sure you have setup the outlet/ delegate/ datasource then these: 确保已设置出口/代表/数据源,然后执行以下操作:

-(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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM