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