Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTextField becomeFirstResponder not work in awakeFromNib

I want to set focus when form load but it didn't work in awakeFromNib.

[myTextField becomeFirstResponder];
like image 807
user1628083 Avatar asked Sep 17 '12 08:09

user1628083


2 Answers

Just to quote the apple docs:

Use the NSWindow makeFirstResponder: method, not this method, to make an object the first responder. Never invoke this method directly.

Do this instead:

[[myTextField window] makeFirstResponder:myTextField];
like image 141
TheAmateurProgrammer Avatar answered Oct 15 '22 20:10

TheAmateurProgrammer


The Swift version to this question:

textField.window?.makeFirstResponder(textField)
like image 33
Leo Dabus Avatar answered Oct 15 '22 20:10

Leo Dabus