I am setting titles for Tableview using SectionIndexTitlesForTableview method. When I swipe a cell, delete button appears next this titles which looks odd. How to hide this indexTitles when delete button appears and show when delete button disappears.

The inEditMode method hides an index when a table is going to be edited
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self inEditMode:YES];
}
-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self inEditMode:NO];
}
//on self.editButtonItem click
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
[self inEditMode:editing];
}
-(void)inEditMode:(BOOL)inEditMode{
if (inEditMode) { //hide index while in edit mode
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;
}else{
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMin;
}
[self.tableView reloadSectionIndexTitles];
}
This might help
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [tableView isEditing] ? nil: @[@"A",@"B",@"C"];
}
- (void)setEditing:(BOOL)editing
{
[super setEditing:editing];
[self reloadSectionIndexTitles];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With