I want to set focus when form load but it didn\'t work in awakeFromNib.
[myTextField becomeFirstResponder];
- (BOOL) becomeFirstResponder
{
if (someCondition)
{
return NO;
}
BOOL retVal = [super becomeFirstResponder];
// do your stuff
return retVal;
}
The Swift version to this question:
textField.window?.makeFirstResponder(textField)
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];