次のコードのようなものを使用して、UIControl を拡張するカスタム ビューに追加された UITextFields を見つけてから、それらに対して rejectFirstResponder を呼び出してキーボードを閉じたいと思いますが、XCode コンパイラはこれを許可せず、"予期しないインターフェイス名 UITextField。式が必要です。" ここで私の目的を達成するための最良の方法は何ですか?
@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