【问题标题】:UITableView Section Index overlapping row delete buttonUITableView Section Index 重叠行删除按钮
【发布时间】:2013-09-28 12:14:45
【问题描述】:

在谷歌、Stackoverflow 和苹果文档上搜索了很多之后,我几乎放弃了。

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

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

就我而言,我没有设置 tableview 或 tableviewcells 宽度的代码,并且无法真正更改节索引。

编辑:

问题是如何让表格视图单元格在它们重叠之前结束,以便删除按钮完全可见。

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

【问题讨论】:

  • 所以...您是在问如何更改部分索引栏的宽度?如何移动删除按钮使其不被掩盖?你只是陈述一个问题,没有问题
  • 我现在添加了一个更具体的问题。我的意图现在更清楚了吗?

标签: ios objective-c uitableview ios7


【解决方案1】:

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

self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];

* 这看起来更好,但索引仍会与您的 tableViewCell 重叠。

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

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

【讨论】:

  • 为 Apple 创建了错误报告。在修复之前,必须这样做。
  • 仅针对 iOS 7 有条件地添加代码。快速的 SO 搜索将出现多种检测 iOS 版本的方法。
【解决方案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];
}

【讨论】:

    【解决方案3】:

    只需在 cellForRowAtIndexPath 中分配任何子视图之前使用此代码

    for (id object in cell.contentView.subviews)
    {
        [object removeFromSuperview];
    }  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      相关资源
      最近更新 更多