Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 目标-C设置集合的委托_Iphone_Objective C - Fatal编程技术网

Iphone 目标-C设置集合的委托

Iphone 目标-C设置集合的委托,iphone,objective-c,Iphone,Objective C,我正在尝试将委托设置为我的UITextfield集合,以便我可以在我的所有文本字段上调用resignFirstResponder。我试过的都没有反应 @property (nonatomic, weak) IBOutletCollection(UITextField) NSMutableArray *textFields; - (void)viewDidLoad { [_textFields enumerateObjectsUsingBlock:^(UITextField *text

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

您是否在.h中添加了
UITextFieldDelegate

@interface MyVC : UIViewController <UITextFieldDelegate>

委托方法没有被调用?集合中是否有文本字段?什么不起作用?textfields应该辞职,无论其代表是谁。正如Wain所说,确保您的集合中确实有文本字段。您确定这些文本字段存在吗?:)我在我的XIB中连接了它们。如果你在枚举块中记录每个文本字段,那会是什么样子?
for (UITextField __strong *field in self.textFields)
   field.delegate = self;