becomeFirstResponder works in viewDidAppear but doesn't work in viewDidLoad

后端 未结 7 1102
傲寒
傲寒 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条回答
  •  我寻月下人不归
    2021-02-13 05:21

    Write viewWillAppear instad of viewDidAppear/viewDidLoad.

    BecauseviewWillAppear method is call at the time of View will appear (in process), for more information about viewWillAppear read this official Document.

    - (void)viewWillAppear:(BOOL)animated
    {
        [self.searchBar becomeFirstResponder];
        [super viewWillAppear:animated];
    }
    

提交回复
热议问题