When I press the edit button I get the round delete icon to the left of the item. When I press the delete icon in the cell it 'turns' but the delete button does not show up so my commitEditingStyle never gets called because I have no delete button to press.
Just for fun...I change the cell to Insert I get the plus icon...I press it and commitEditingStyle is called.
I do not understand why I am not getting the delete button.
I have a UIViewController that I am showing in a popover. I am adding a UITableView to like so...
audioTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 303)];
audioTable.delegate = self;
audioTable.dataSource = self;
[self.view addSubview:audioTable];
I am using a custom cell with two labels in it to display text.
Here is the custom cell initWithFrame...
primaryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25 ,8, 275, 25)];
primaryLabel.font = [UIFont systemFontOfSize:14];
secondaryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25 ,28, 275, 25)];
secondaryLabel.font = [UIFont systemFontOfSize:12];
[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:secondaryLabel];
[self.contentView sendSubviewToBack:primaryLabel];
[self.contentView sendSubviewToBack:secondaryLabel];
I have a delete button in a toolbar in the view controller that is hooked up to the edit call. Here is what I am doing in the edit call which is getting called fine because I am getting the delete symbol in the cell...
if([self.audioTable isEditing]) {
[button setTitle:@"Edit"];
[super setEditing:NO animated:NO];
[self.audioTable setEditing:NO animated:YES];
} else {
[button setTitle:@"Done"];
[super setEditing:YES animated:NO];
[self.audioTable setEditing:YES animated:YES];
}
I have implemented the following...
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
//i don't think i need to implement this really
return YES;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//do delete stuff
}
}
Like I said everything is working normally, button presses and all work...just no delete button.
If you are using custom tableview not the TVController. You must set atleast three delegates
Swift 4.2
And most important is to add 'tableView.isEditing = true' in the viewDidload :)
Remember to set the style of the delete button
I know you fixed it using a
UITableViewController
but I couldn't in my case.Looking around I just found the answer here, you need more plumbing to get the job done. Fortunately its pretty easy. Add this to the
UIViewController
containing a reference to yourUITableView
I ran into the same issue. The problem was that my tableView's frame was not being properly resized inside the popover. In reality the delete button was being displayed but it was outside the bounds of the popover so it couldn't be seen.
I fixed this by ensuring the
tableView
resizes appropriately. For me this meant setting the tableView'sautoresizingMask
like this:The reason others were able to fix this by switching to a
UITableViewController
is because itstableView
is properly resized.I had to work around it by using a different mechanism. I did a test and when I used a
UITableViewController
it worked fine. When I added aUITableView
to aUIViewController
, implementing the same thing as theUITableViewController
does, it does not work. I do not know what I missed, but using theUIViewController
as opposed to theUITableViewController
caused the delete button to not appear.The problem is that you're adding the labels using addSubview: to the cell's content view, and as they're added as last, they hide the other parts of the cell. Push them into the background by calling: