簡體   English   中英

Objective-C設置集合的委托

[英]Objective-C setting the delegate for a collection

我試圖將委托設置為我的UITextfield集合,以便可以在所有resignFirstResponder上調用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>

也可以嘗試:

for (UITextField __strong *field in self.textFields)
   field.delegate = self;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM