becomeFirstResponder works in viewDidAppear but doesn't work in viewDidLoad

后端 未结 7 1100
傲寒
傲寒 2021-02-13 04:49

My Application has a modal view controller, including a search bar. When the view comes up, I want the search bar to be focused. I tried [self.searchBar becomeFirstRespond

7条回答
  •  梦毁少年i
    2021-02-13 05:00

    all the IBOutlet objects are loaded in viewDidLoad,if you are calling the method in viewDidLoad then that action not performed because before the objects are loaded we can't do anything that's whybetter to write that code in

    -(void)viewWillAppear:(BOOL)animated{
    //write here
    } 
    

    then it works fine.

提交回复
热议问题