当单元格上出现删除按钮时,隐藏节标题索引。

3
我正在使用SectionIndexTitlesForTableview方法为Tableview设置标题。当我滑动一个单元格时,删除按钮会出现在这些标题旁边,看起来很奇怪。如何在删除按钮出现时隐藏这些索引标题,并在删除按钮消失时显示它们。
3个回答

2

inEditMode方法在编辑表格时隐藏索引。

-(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];
}

1
这可能会有所帮助。
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return [tableView isEditing] ? nil: @[@"A",@"B",@"C"];
}

- (void)setEditing:(BOOL)editing
{
    [super setEditing:editing];
    [self reloadSectionIndexTitles];
}

0
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
        {
        _someBoolean = YES;
       [tableView reloadData];
        return YES;
        }

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
            if (editingStyle == UITableViewCellEditingStyleDelete) {
                _someBoolean = NO;
                [tableView reloadData];
            }    
        }


- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
        {
                return _someBoolean ? nil : _yourTitlesArray;
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接