0

我正在尝试将委托设置为我的 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;
}
4

1 回答 1

0

UITextFieldDelegate在.h中添加了吗?

@interface MyVC : UIViewController <UITextFieldDelegate>

也可以尝试:

for (UITextField __strong *field in self.textFields)
   field.delegate = self;
于 2013-06-24T22:07:11.270 回答