Daan Lemmen
Daan Lemmen

Reputation: 131

Custom UITableViewCell is not showing indent while editing

I'm on iOS 7, have an UITableViewController, with a UITableView (linked up the data source and delegate) and trying to use editing. I use a custom UITableViewCell, with Dynamice Prototype in UIStoryboard. When I click on the edit button (self.editButtonItem), you see the name change to done, but the are no indent icons (- icon). Swiping from the cell works, I get a delete button.

Here is my code:

self.navigationItem.leftBarButtonItem = self.editButtonItem;

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}

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

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

All of my content is in the contentView

Upvotes: 0

Views: 978

Answers (2)

Daxesh Nagar
Daxesh Nagar

Reputation: 1415

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


    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        [arr removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
    }
}



- (IBAction)editbtn:(id)sender {

    if (self.tableView.editing) {
        self.tableView.editing = NO;
        [edit setTitle:@"Edit" forState:UIControlStateNormal];
    }
    else{
        self.tableView.editing = YES;
        [edit setTitle:@"Done" forState:UIControlStateNormal];
    }
}

I think this code help you.

Upvotes: 3

Daan Lemmen
Daan Lemmen

Reputation: 131

In a UIViewController self.editButtonItem doesn't work, you need to create a custom button.

Upvotes: -2

Related Questions