UITableView Section Index重叠行删除按钮

时间:2013-09-28 12:14:46

标签: ios objective-c uitableview ios7

经过大量搜索Google,Stackoverflow和Apple文档之后,我几乎放弃了。

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

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);

我也尝试了同样的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);

3 个答案:

答案 0 :(得分:10)

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

self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];

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

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

// allow editing
[self.tableView setEditing:YES animated:YES];
// hides the index
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;

答案 1 :(得分: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];
}

答案 2 :(得分:0)

在cellForRowAtIndexPath

中分配任何子视图之前,只需使用此代码
for (id object in cell.contentView.subviews)
{
    [object removeFromSuperview];
}