Something weird is happening? As I tested this on all the simulators including the physical phone, the search bar renders fine. However, when I quit Xcode and open the application on the phone, the search bar would not render with the correct width. (It would be all bunched up. It's hard to debug because this program isn't visible in any of the simulators.) Part of the code:
override func viewDidLoad()
{
super.viewDidLoad()
initList()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
initSearchController()
}
func initSearchController()
{
searchController.loadViewIfNeeded()
searchController.searchResultsUpdater = self
searchController.searchBar.sizeToFit()
searchController.searchBar.frame.size.width = self.view.frame.size.width
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.enablesReturnKeyAutomatically = false
searchController.searchBar.returnKeyType = UIReturnKeyType.search
searchController.isActive = false
searchController.searchBar.placeholder = "Search poetry, lyrics, arias ..."
searchController.definesPresentationContext = true
searchController.searchBar.delegate = self
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
}
override func viewDidLoad()
{
super.viewDidLoad()
initList()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
initSearchController()
}
func initSearchController()
{
searchController.loadViewIfNeeded()
searchController.searchResultsUpdater = self
searchController.searchBar.sizeToFit()
searchController.searchBar.frame.size.width = self.view.frame.size.width
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.enablesReturnKeyAutomatically = false
searchController.searchBar.returnKeyType = UIReturnKeyType.search
searchController.isActive = false
searchController.searchBar.placeholder = "Search poetry, lyrics, arias ..."
searchController.definesPresentationContext = true
searchController.searchBar.delegate = self
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
}