12

I know this is a long write-up, but it's just one issue I promise.

The Setup

I'm getting some very strange behavior with a UISearchController. Let me describe the hierarchy, then I'll explain step by step what happens in my video:

The first view you see is a regular ViewController, with a tableView and the UISearchController as completely separate entities. The UISearchController has its own searchResultsController that I set when I create it:

let searchResultsController = MyResultsControllerClass() searchController = UISearchController(searchResultsController: searchResultsController) 

That's the basic setup.

The Behavior

A link to a video of the behavior

The MyResultsControllerClass has a tableView, as well as a pointer back to the master view controller all these views are housed in. When the searchController's searchBar begins searching, you see that tableView show up. Then I tap a result, Programming Club. The MyResultsControllerClass uses the pointer to the master view to push a new view controller (just details about that event) like so:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let activityDetail = ActivityDetailViewController(nibName: nil, bundle: nil, activity: searchResults[indexPath.row]) parentController?.navigationController?.pushViewController(activityDetail, animated: true) } 

You can see this happen behind the searchBar, but the searchController is not "covered up" by the presented view! This is my issue. As you can see, I can still interact with it. When I press "Cancel", it finally disappears.

What I've tried

Now, I thought this might have to do with the fact that a UISearchController is in fact a UIViewController, if I understand correctly. So I attempted pushing from the UISearchController, nothing happens. I tried embedding the UISearchController in its own UINavigationController and pushing from searchController.navigationController, nothing happens. I can completely cancel the editing before pushing, but I want the editing to still exist when they navigate back.

What am I doing wrong? Is there a better way to do this?

1
  • the linked video is private, I couldn't open it. Commented May 8, 2016 at 20:04

1 Answer 1

39

I have the same exact issue, I have solved it by setting:

self.definesPresentationContext = YES; 

on the view controller that presents the UISearchController. This is recommended by Apple in WWDC session 228, read about it here: http://asciiwwdc.com/2014/sessions/228.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.