I’d like to use something like the following code to find the UITextFields that have been added to my custom view which extends UIControl and then call resignFirstResponder on them to dismiss the keyboard but the XCode compiler won’t allow this and gives the message “Unexpected interface name UITextField. Expected expression.” What is the best way to achieve my desired aim here?
@interface MyCustomView : UIControl
@end
@implementation MyCustomView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
/* Dismiss the keyboard associated with any UITextFields in this view */
for (id subview in self.subviews) {
if ([subview isKindOfClass: UITextField] ||
[subview isMemberOfClass: UITextField]) {
[subview resignFirstResponder];
}
}
}
@end
You need to do the following to get the UITextField class: