Nico
Nico

Reputation: 6359

Tap on a UITableView Index (A...Z) when a UISearchController's searchBar is active

I have a UITableView coupled to a UISearchController.

The connection is made by putting the seach bar as the table view header like this:

tableView.tableHeaderView = searchController.searchBar

I do the link between the index bar on the side and the sections header like this:

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

This works fine.

When the search bar is active, it stays visible all the time when scrolling (which is the intended behaviour).

My problem is when I tap on one of the index letter on in the index bar on the side. It scrolls to the section header, but as the search bar is always visible while being active, we can't see the section header title and part of the first row of the section, we have to scroll manually.

Like on this snapshot, I tapped on the index letter L:

enter image description here

Is there a way to fix it (any hack accepted)?

Upvotes: 0

Views: 557

Answers (1)

rkyr
rkyr

Reputation: 3251

If you want UISearchBar to be visible over UITableView you should try to set insets for your tableView. Such as

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

Upvotes: 2

Related Questions