【问题标题】:iOS 8 - Search display controller shows white space at rightiOS 8 - 搜索显示控制器在右侧显示空白
【发布时间】:2015-03-02 11:48:45
【问题描述】:

在应用程序中使用搜索显示控制器,它在 iOS 7 中运行良好,但在 iOS 8 中,它在搜索显示表的右侧显示如下所示的空白

尝试了很多,但没有得到任何解决方案。

【问题讨论】:

  • 这有可能在更宽的手机上运行吗?如果您使用的是自定义 tableView 单元格,请确保背景(红色)没有硬编码以适合较小的手机
  • @DevC 它不是硬编码的,我正在使用 iOS 7 检查 iPhone 5S 工作正常;但是使用带有 iOS 8 的 iPhone 5S 会出现上述问题
  • 你检查了单元格的附件类型吗?

标签: ios swift uisearchdisplaycontroller


【解决方案1】:

这可能是因为 layoutMargins。尝试将此方法添加到表视图的委托中,看看是否按预期工作:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Remove seperator inset
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }

    // Explictly set your cell's layout margins
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }

}

【讨论】: