UITableView Section Index overlapping row delete button

后端 未结 3 796
醉话见心
醉话见心 2020-12-30 06:15

After quite a lot searching around Google, Stackoverflow and apples documentation, I have almost given up.

I am making an app to index costumers and because of a pot

相关标签:
3条回答
  • 2020-12-30 06:26

    As a simple work-around we resolved the visual overlap of the index by setting the background color of the index to clearColor.

    self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
    

    * This looks visually better, but the index will still overlap your tableViewCell.

    Another possible work-around would be to hide the index bar when entering edit mode:

    // allow editing
    [self.tableView setEditing:YES animated:YES];
    // hides the index
    self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;
    
    0 讨论(0)
  • 2020-12-30 06:32

    Just Use this code before allocating any subview in cellForRowAtIndexPath

    for (id object in cell.contentView.subviews)
    {
        [object removeFromSuperview];
    }  
    
    0 讨论(0)
  • 2020-12-30 06:33

    The inEditMode method should do the trick. Below I embed a complete code that hides the index while editing and shows it again when the editing is done.

    -(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];
    }
    
    0 讨论(0)
提交回复
热议问题