UITableView Section Index重叠行删除按钮

Stj*_*ard 13 objective-c uitableview ios ios7

经过大量搜索谷歌,Stackoverflow和苹果文档,我几乎放弃了.

我正在制作一个应用程序来索引客户,并且由于可能很长的列表,我使用段索引来更快地导航.我的问题如下图所示.

http://i.stack.imgur.com/i2tTx.png

当我拖动项目以显示删除按钮时,它部分隐藏在我的部分索引栏下方.

我没有代码设置tableview或tableviewcells宽度,并且就我而言,部分索引无法真正改变.

编辑:

问题是我如何让tableview单元格在重叠之前结束,因此删除按钮是完全可见的.

编辑2:

我已经尝试过将单元框架设置得更小而没有任何运气.

cell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width-30, cell.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

我也尝试了同样的tableview,但因为它在UITableViewController中,它无法调整大小.

self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width-30, self.tableView.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

Min*_*sai 10

作为一个简单的解决方法,我们通过将索引的背景颜色设置为clearColor来解决索引的视觉重叠.

self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

*这在视觉上看起来更好,但索引仍将与tableViewCell重叠.

另一种可能的解决方法是在进入编辑模式时隐藏索引栏:

// allow editing
[self.tableView setEditing:YES animated:YES];
// hides the index
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;
Run Code Online (Sandbox Code Playgroud)

  • 为Apple创建了一个错误报告.在修复之前,必须这样做. (2认同)

Ale*_*xey 6

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];
}
Run Code Online (Sandbox Code Playgroud)