Navigation bar disappears when reloading data using UISearchController

My application works so that I have a UISearchController in a reusable view inside a UICollectionViewController. When I click on the search bar, I click any of the results and launches a notification to reload the View collection to reflect the changes.

lazy var searchController: UISearchController = { let tableViewController = UITableViewController(style: .Plain) tableViewController.tableView.dataSource = self tableViewController.tableView.delegate = self tableViewController.tableView.registerClass(StoreListCell.self, forCellReuseIdentifier: "MiniStoreCell") let searchController = UISearchController(searchResultsController: tableViewController) searchController.searchResultsUpdater = self searchController.searchBar.frame = CGRect(x: 0, y: 0, width: CGRectGetWidth(self.collectionView.frame), height: 44) return searchController }() override func viewDidLoad() { super.viewDidLoad() definesPresentationContext = true collectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "SearchView") let layout = collectionView.collectionViewLayout as UICollectionViewFlowLayout layout.headerReferenceSize = CGSize(width: CGRectGetWidth(collectionView.frame), height: 44) token = RLMRealm.defaultRealm().addNotificationBlock({ [unowned self] (notification, realm) -> Void in self.categories = Category.allObjects().sortedResultsUsingProperty("name", ascending: true) self.collectionView.reloadData() }) } override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { let searchView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "SearchView", forIndexPath: indexPath) as UICollectionReusableView searchView.addSubview(searchController.searchBar) searchController.searchBar.sizeToFit() return searchView } 

Since reloadData also reloads the reusable view in which the search bar is located, this leads to the disappearance of the navigation bar, leaving me stuck in searchresultsController enter image description here

Front enter image description here

After

+3
source share

All Articles