当 UISearchController 的搜索栏处于活动状态时,点击 UITableView 索引 (A...Z)
Tap on a UITableView Index (A...Z) when a UISearchController's searchBar is active
我有一个 UITableView 耦合到 UISearchController。
通过将搜索栏作为 table 视图 header 建立连接,如下所示:
tableView.tableHeaderView = searchController.searchBar
我在侧面的索引栏和 header 部分之间做 link 是这样的:
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)
}
}
这很好用。
当搜索栏处于活动状态时,它在滚动时始终保持可见(这是预期的行为)。
我的问题是当我点击侧面索引栏中的其中一个索引字母时。它滚动到 header 部分,但由于搜索栏在活动时始终可见,我们看不到 header 部分的标题和部分第一行的一部分,我们必须滚动手动。
就像这张快照一样,我点击了索引字母 L
:
有没有办法修复它(接受任何破解)?
如果您希望 UISearchBar 在 UITableView 上可见,您应该尝试为您的 tableView 设置 insets。如
[self.tableView setContentInset:UIEdgeInsetsMake(44, 0, 0, 0)];
我有一个 UITableView 耦合到 UISearchController。
通过将搜索栏作为 table 视图 header 建立连接,如下所示:
tableView.tableHeaderView = searchController.searchBar
我在侧面的索引栏和 header 部分之间做 link 是这样的:
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)
}
}
这很好用。
当搜索栏处于活动状态时,它在滚动时始终保持可见(这是预期的行为)。
我的问题是当我点击侧面索引栏中的其中一个索引字母时。它滚动到 header 部分,但由于搜索栏在活动时始终可见,我们看不到 header 部分的标题和部分第一行的一部分,我们必须滚动手动。
就像这张快照一样,我点击了索引字母 L
:
有没有办法修复它(接受任何破解)?
如果您希望 UISearchBar 在 UITableView 上可见,您应该尝试为您的 tableView 设置 insets。如
[self.tableView setContentInset:UIEdgeInsetsMake(44, 0, 0, 0)];