0

Just finished following Ray Wenderlich's "UI Search Controller" tutorial in which I create a search bar with scope button items:

https://www.raywenderlich.com/113772/uisearchcontroller-tutorial

I got it working no problem, with the small exception that the scope buttons overlap the first result of my tableview scrollview:Picture Here

In my app I'm using a tableView which is embedded inside a UIViewController, I'm guessing this may be the problem. I have "Adjusts Scroll View Insets" checked on my UIViewController, didn't solve the problem. Even tried unchecking it on the weird chance that may have been the problem, still not working.

I'm thinking the problem has to do with the fact that the searchBar is being added as a headerView of the tableView in the tutorial:

 tableView.tableHeaderView = searchController.searchBar

However, I have no idea why it wouldn't cause any problems for what looks like a UINavigationController, but it would cause problems for someone embedding it on a tableView within a UITableViewController.

Any help/workaround suggestions are much appreciated! Thank you so much in advance.

EDIT: Code instantiating search controller, as following the Wenderlich tutorial:

        searchController.searchBar.scopeButtonTitles = ["All","party", "hangout", "recreation", "event", "other"]
        searchController.searchBar.tintColor = UIColor().crimson()

        searchController.searchBar.delegate = self

        //MARK: Search controller initialization
        searchController.searchResultsUpdater = self
        searchController.dimsBackgroundDuringPresentation = false
Colin Warn
  • 371
  • 1
  • 3
  • 19
  • Can you show the code of adding scope buttons ? what is the height of this scope button bar? – 3stud1ant3 Aug 09 '17 at 16:58
  • @user1000 added the code used to add scope buttons to the original post. Never had to adjust the height of the scope bar, looks like it's about 20-30 height eyeballing it though. – Colin Warn Aug 09 '17 at 17:11
  • Please show the storyboard where you are setting the constraints for tableview – 3stud1ant3 Aug 09 '17 at 17:14
  • http://imgur.com/a/cX9QY – Colin Warn Aug 09 '17 at 17:17
  • Storyboard picture. Don't have enough rep points to post a second picture in the original post, imgur it is. Let me know if you need me to snapshot a certain part of the storyboard. – Colin Warn Aug 09 '17 at 17:17
  • Have you written this statement in your code: definesPresentationContext = true, if not please add before searchController.dimsBackgroundDuringPresentation = false and tell me the result – 3stud1ant3 Aug 09 '17 at 17:22
  • @user1000 tried that, moved it before the dimsBackground method call, still not working. – Colin Warn Aug 09 '17 at 17:31
  • I checked it but problem is due to adding of nav bar in storyboard, without it , works perfectly but when nav bar is added it causes problem – 3stud1ant3 Aug 09 '17 at 18:24
  • @user1000 any ideas what the workaround would be? Tried hiding the navBar whenever the search was clicked, that didn't seem to solve it. – Colin Warn Aug 09 '17 at 19:36
  • @user1000 nevermind figured out a workaround! implementing the heightforHeaderInSection solves the problem: https://stackoverflow.com/questions/29264571/uisearchcontrollers-search-bar-overlaps-first-tableview-cell – Colin Warn Aug 09 '17 at 19:47
  • Good work, I have learnt from this question , Thanks – 3stud1ant3 Aug 10 '17 at 02:36
  • I think you should post an answer that how you solved your problem, this will help others – 3stud1ant3 Aug 10 '17 at 02:43

1 Answers1

0

Answer discovered: Implement the heightForHeaderInSection method in tableView and return the height. Answer can be found here:

https://stackoverflow.com/a/32996842/7389684

Colin Warn
  • 371
  • 1
  • 3
  • 19