【问题标题】:Tap on a UITableView Index (A...Z) when a UISearchController's searchBar is active当 UISearchController 的 searchBar 处于活动状态时,点击 UITableView 索引 (A...Z)
【发布时间】:2015-09-10 05:33:53
【问题描述】:

我有一个与 UISearchController 耦合的 UITableView。

通过将搜索栏作为表格视图标题进行连接,如下所示:

tableView.tableHeaderView = searchController.searchBar

我在侧面的索引栏和部分标题之间进行链接,如下所示:

func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
    if searchPredicate != nil {
        for (index, section) in enumerate(filteredSections) {
            if section.name == title {
                return index
            }
        }
        return 0
    } else {
        return self.fetchedResultsController.sectionForSectionIndexTitle(title, atIndex: index)
    }
}

这很好用。

当搜索栏处于活动状态时,它在滚动时始终保持可见(这是预期的行为)。

我的问题是当我点击侧面索引栏中的一个索引字母时。它滚动到节标题,但由于搜索栏在活动时始终可见,我们看不到节标题标题和节第一行的一部分,我们必须手动滚动。

就像这张快照一样,我点击了索引字母L

有没有办法修复它(接受任何黑客攻击)?

【问题讨论】:

    标签: ios swift uitableview uisearchcontroller


    【解决方案1】:

    如果您希望 UISearchBar 在 UITableView 上可见,您应该尝试为您的 tableView 设置插图。比如

    [self.tableView setContentInset:UIEdgeInsetsMake(44, 0, 0, 0)];
    

    【讨论】:

    • 我同意这个答案。手动滚动 tableView 应该是可以接受的修复。
    • 我也同意。谢谢。只是为将来的读者提供精确度,您必须在搜索栏处于活动状态时添加插图,并在搜索栏不活动时重新设置。
    • 其实有问题。当我更改内容插图时,搜索栏的灰色部分变得有点透明。知道如何解决这个问题吗?
    • searchController.searchBar.translucent = false 修复它。
    猜你喜欢
    • 2015-12-17
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多