When assigning focus via becomeFirstResponder to UISearchController's UISearchBar, the keyboard does not appear

后端 未结 10 869
感动是毒
感动是毒 2020-12-14 07:01

I\'ve spent quite a bit of time searching online and talking to other developers about this issue to no avail. The exact issue is described in this SO post (Focus on the UIS

10条回答
  •  自闭症患者
    2020-12-14 07:20

    On iOS 9 I've found its sufficient to delay becomeFirstResponder() to the next run loop:

    func focusSearchField() {
        searchController?.active = true
    
        // skipping to the next run loop is required, otherwise the keyboard does not appear
        dispatch_async(dispatch_get_main_queue(), { [weak self] in
            self?.searchController?.searchBar.becomeFirstResponder()
        })
    }
    

提交回复
热议问题