Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Result of call to 'becomeFirstResponder()' is unused UITextField inside UITableView

I'm trying to put cursor in first UITextField inside UITableView and let keyboard to be displayed as wrote like that.

if (indexPath.row == 0) {
    cell.inputTextField.becomeFirstResponder()
}

But warning showing like that.

Result of call to 'becomeFirstResponder()' is unused

How to put cursor in first UITextField and let KeyBoard to be displayed?

like image 763
PPShein Avatar asked Feb 21 '18 07:02

PPShein


2 Answers

I meet it when override 'becomeFirstResponder',if you want remove it,you can use @discardableResult

like image 24
tao tan Avatar answered Nov 07 '22 21:11

tao tan


Since becomeFirstResponder() returns a Bool, you are supposed to check the return value according to warning.

If you don't need to know becomeFirstResponder was successful, you should write:

let _ = cell.inputTextField.becomeFirstResponder()
like image 113
Andreas Oetjen Avatar answered Nov 07 '22 21:11

Andreas Oetjen