UISearchController does not deviate when View push

I know this is a long review, but this is just one problem that I promise.

Customization

I get very strange behavior with a UISearchController. Let me describe the hierarchy, then I will explain step by step what happens in my video:

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

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

This is a basic setting.

Behavior

Behavior Video Link

MyResultsControllerClass has a tableView, as well as a pointer back to the main view controller. All of these views are placed inside. When the SearchController searchBar begins to search, you see that the tableView is being displayed. Then I click the result, programming the club. MyResultsControllerClass uses a pointer to the main view to push the new view controller (only details about this event) as follows:

 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 that this happens behind the search, but the searchController is not "closed" by the submitted view! It is my problem. As you can see, I can still interact with him. When I click Cancel, it finally disappears.

What i tried

Now I thought that this could be due to the fact that the UISearchController is actually a UIViewController, if I understand correctly. So I tried to click from UISearchController, nothing happens. I tried to embed the UISearchController in my own UINavigationController and clicking on searchController.navigationController nothing happens. I can completely cancel the editing before clicking, but I want the editing to still exist when they move backward.

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

+11
ios search iphone xcode swift
Apr 13 '15 at 16:56
source share
1 answer

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

 self.definesPresentationContext = YES; 

on the view controller that represents the UISearchController. This is recommended by Apple at the WSDC 228 session, read here: http://asciiwwdc.com/2014/sessions/228 .

+35
Apr 16 '15 at 16:04
source share



All Articles