Kodeco Forums

UISearchController Tutorial: Getting Started

Learn how to improve your app by adding a search feature with dynamic filtering, and a scope bar in this UISearchController Tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/472-uisearchcontroller-tutorial-getting-started

Any workarounds for the issue in iOS11 where the scope buttons overlaps with the tableView? Can the tableview / UITableViewController be resized to adjust to the height of the search bar with scope buttons? Not sure what to try …

@tomelliott Do you have any feedback regarding this? Thank you - much appreciated! :]

Hi @zulfishah. I’ve not given this too much thought yet to be honest. Given this appears to be a regression in the iOS 11 beta (compared to iOS 10 and 9) I’m hoping Apple will fix it before the general release.

I have a radar open and Apple have requested more information from me rather than closed as expected behaviour. So fingers crossed!

Thanks. The problem’s still in Beta7, so not sure if it’ll be fixed; would be very problematic for me, so looking for a potential workaround. Removing the scope bar is of course the fallback, though will get terrible feedback for it.

Is there any documentation for implementing this into a different app. I am trying to set up the splitview navigations items to setup the tableview but am continuously getting a sigabert error. specifically in the app delegate swift file

Thanks for the tutorial. Could you advise what adjustments you would make for a table containing sections which is backed by a two-dimensional array instead of a single dim. one.

Hi, @tomelliott!
Nice tutorial, thank you!
Just found one bug (also found in complete sample project): filtering actually doesn’t work properly. For example, if you type “che” waiting for “Soul Chew” to be in filtered result, but result is empty. Ot try “Coi” to filter “Chocolat Coin” - doen’t work too.
If search term contain more than two symbols - result is unpredictable.

I think int’s filtered, but not shown

when i run app in ios 11, rotate iphone. UI incorrect

@zulfishah @tomelliott Did any of you solve this? I still have the problem that the scope buttons overlap the table view! Xcode 9.0 release.

@bass @tomelliott After two hours of searching, it’s not a bug.

Fixed by change this line:

tableView.tableHeaderView = searchController.searchBar

to

if #available(iOS 11.0, *) {
   navigationItem.searchController = searchController
   navigationItem.hidesSearchBarWhenScrolling = false
} else {
  tableView.tableHeaderView = searchController.searchBar
}

Reference here:

1 Like

@benck Thanks a lot, you really saved my day. Really appreciate you taking the time to share this!

@tomelliott : I have few buttons on my tableview cell such “copy” “star”. copy copies the content of tableview cell which is text. star marked it favorite.

Problem I am facing is, when I search and filtered results show up I cant tap on buttons in cell. that dismisses the searchController and I am back to tableView.

Any pointers for me how to solve this problem?

@tomelliott tried the above, but in ios 11, scopeButtonTitles display incorrect?
You run it on xCode9 ios 11. you will see problem as me when you press key command + → to Landscape iphone

Anybody tried it on iPhone X simulator? I’m facing some issues with status bar.

Hi all.

Thanks for your patience and apologies with the delay replying. I’ve been away on holiday (well actually getting married + a honeymoon :smile: ). I’ll take a look through all of these over the weekend and get fixes out for the iOS 11 bugs.

@pavoleg I can’t reproduce this, works fine here.

I’d suggest checking your filtering code with that in the tutorial! If that doesn’t work, attach your project file here and I’ll take a look for you.

@tomelliott Do you fix it this way?

When enable Landscape Left, scopeButtonTitle display incorrect.haha

Tom, thanks for the great tutorial, I used the older version and found your newer version while inspecting an error upon rotation. I have used the if #available(iOS 11.0, *) fix to show the scope bar. However, I am finding out that if I rotate the app to landscape and then back to portrait the scope bar comes out under the searchbar. If I pull on the table view the scope bar comes out. I even tried adjusting the size of the scope bar view upon rotation. Any ideas? Thanks so much for all your team does with these great tutorials!

Douglas