In Mac OS X, you can find the first responder like this:
[[self window] firstResponder]
Is there any way of doing it in iOS? Or do you need to enumerate the child controls and send an isFirstResponder
message to each one?
You would need to iterate over all of the child controls and test the isFirstResponder
property. When you encounter TRUE
, break out of the loop.
UIView *firstResponder;
for (UIView *view in self.view.subviews) //: caused error
{
if (view.isFirstResponder)
{
firstResponder = view;
break;
}
}
BETTER SOLUTION
See Jakob's answer.