Cannot set searchBar as firstResponder

前端 未结 21 1900
别跟我提以往
别跟我提以往 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:11

    Very similar to other answers, but I had to access the main queue in the ViewDidAppear. The SearchBarController can't be acted upon until the View appears and then can only be done so in the main queue for UI:

    searchController.active = true  // doubtful whether this is needed
    
            dispatch_async(dispatch_get_main_queue(), {
                self.searchController.searchBar.becomeFirstResponder()
            });
    

提交回复
热议问题