performSearch() in Search class

Hi all,

The completion of performSearch given by performSearch() in SearchViewController class is

    if let category = Search.Category(rawValue: segmentedControl.selectedSegmentIndex) {
        
        search.performSearch(for: searchBar.text!,
                             category: category,
                             completion: { success in
                                if !success {
                                    self.showNetworkError()
                                }
                                self.tableView.reloadData()
                                self.landscapeViewController?.searchResultsReceived()
        })
        tableView.reloadData()
        searchBar.resignFirstResponder()
    }

Is tableView.reloadData() is necessary if the screen goes to landscape? If not, why doesn’t use a if statement to call them separately according to different screen type(portrait or landscape )?

I would have to look at the code again to be sure (I’m going by memory here) but if recall correctly after a search both portrait and landscape views reload the data so that both views have the same search results. So the call to landscapeViewController within the closure is not to navigate to that view but to notify the view that the search results have changed.

If you are in landscape view at this point, you’ll see the changed results. If not, you’ll see the results in portrait mode but the landscape view will have the new results for when you next rotate the device.

This topic was automatically closed after 166 days. New replies are no longer allowed.