简体   繁体   中英

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 :

在此处输入图片说明

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

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)];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM