Question

I have a core data/ uitableview based app. Actually 80% of the code so far is equal to the Apple Sample app 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.

alt text

The differences in code with CoreDataRecipes:

  1. I have custom UITabelview cell with a nib file instead of code only.
  2. My Tableview is an Outlet inside my class view. So my class RecipeListTableViewController is an UIViewController with Tableview delegates instead of a UITableViewController

What I tried:

  • The Tableview works fine. 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. It should be by default but to make sure I added:

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

  • I checked if the delete icons where not behind my cellview. There are not. I now think that the cell behaviour of moving to the right is handled by 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. Nothing changed when entering the edit mode. But when I swipe, now I see my subview in one row:

alt text

Anyone any ideas? It must be something simple.

Was it helpful?

Solution

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. The default is set to return NO

OTHER TIPS

I think you have not added the line tableView.editing=YES on clicking the Edit button

Try by setting it!

Since yours is a UIViewController, the tableview doesnt get the setEditing call. 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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top