UITableView reloadData automatically calls resignFirstResponder

后端 未结 13 1394
天命终不由人
天命终不由人 2020-12-02 22:44

I have this UITableView with custom cells that can get only predefined values, therefore I use a UIPickerView as their inputView. All is jolly good until I edit a field and

13条回答
  •  一整个雨季
    2020-12-02 23:18

    You can solve this issue by temporarily transferring the first responder status to other object. Usually you transfer the control of input view to your ViewController. Since your UIViewController also inherits from UIResponder, you can do something like this:

    on didSelect { ....

    [yourViewController becomeFirstRespoder];

    [_tableView reloadData];

    [yourInputField becomeFirstResponder];

    .... }

    Thus, once the table is reloaded, you can transfer firstResponder status back to your label/field. By default, the canBecomeFirstResponder is set to NO. So you might need to override the same in your ViewController. Also, you might need to make the inputView for your view controller the same as your UIPicker, otherwise it might just dismiss your picker and display a keyboard.

提交回复
热议问题