becomeFirstResponder works in viewDidAppear but doesn't work in viewDidLoad

后端 未结 7 1084
傲寒
傲寒 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:23

    This will help:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.quantifyTextField becomeFirstResponder];
        });
    }
    

提交回复
热议问题