iOS8 Cannot hide cancel button on search bar in UISearchController

后端 未结 9 618
后悔当初
后悔当初 2021-01-01 12:26

My goal is to prevent the cancel button from appearing in a search bar in a UISearchController. I started with Apple\'s Table Search with UISearchController sample code and

9条回答
  •  暖寄归人
    2021-01-01 12:55

    Just subclass your UISearchController and do the following:

    class CustomSearchController: UISearchController {
    
       override func viewDidLayoutSubviews() {
           super.viewDidLayoutSubviews()
           searchBar.showsCancelButton = false
       }
    }
    

    This was the easiest solution I could came up with in order to solve the flashing cancel-button issue.

提交回复
热议问题