我正在尝试将委托设置为我的UITextfield集合,以便我可以在所有文本字段上调用resignFirstResponder
。我试过的没有回应。
@property (nonatomic, weak) IBOutletCollection(UITextField) NSMutableArray *textFields;
- (void)viewDidLoad
{
[_textFields enumerateObjectsUsingBlock:^(UITextField *textfield, NSUInteger idx, BOOL *stop)
{
textfield.delegate=self;
}];
}
- (BOOL) textFieldShouldReturn:(UITextField *)textFields
{
NSLog(@"textFieldShouldReturn Fired :)");
[_textFields enumerateObjectsUsingBlock:^(UITextField *textfield, NSUInteger idx, BOOL *stop)
{
[textfield resignFirstResponder];
}];
return YES;
}
答案 0 :(得分:0)
您是否在.h?
中添加了UITextFieldDelegate
@interface MyVC : UIViewController <UITextFieldDelegate>
也许可以试试:
for (UITextField __strong *field in self.textFields)
field.delegate = self;