Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide sectionindextitles when delete button appears on the cell

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.

enter image description here

like image 658
Anand Avatar asked Feb 25 '26 04:02

Anand


2 Answers

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];
}
like image 97
Alexey Avatar answered Feb 27 '26 17:02

Alexey


This might help

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return [tableView isEditing] ? nil: @[@"A",@"B",@"C"];
}

- (void)setEditing:(BOOL)editing
{
    [super setEditing:editing];
    [self reloadSectionIndexTitles];
}
like image 20
ИIHIL Avatar answered Feb 27 '26 16:02

ИIHIL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!