Cannot set searchBar as firstResponder

前端 未结 21 1864
别跟我提以往
别跟我提以往 2020-11-30 01:33

I have a searchBar I\'m setting in a tableviewcontroller. i\'ve referenced this similar question UISearchBar cannot become first responder after UITableView did re-appear bu

21条回答
  •  天命终不由人
    2020-11-30 02:28

    To me, there’s a quite big lag when using viewDidAppear. It can be better to use becomeFirstResponder asynchronously in viewDidLoad (tested with iOS 10, Swift 3):

    override func viewDidLoad() {
        super.viewDidLoad()
    
        DispatchQueue.main.async {
            searchController.searchBar.becomeFirstResponder()
        }
    }
    

提交回复
热议问题