我在子视图中有一个文本字段,我已经对其进行了子类化。现在我想在我原来的视图中调用 textField 的委托方法。
我用这段代码试过了,但不知何故没有调用这些方法:
NewImageViewController *ni = [[NewImageViewController alloc] init];
textField.delegate = ni;
“NewImageViewController”是我的原始视图。
编辑:
我的子类.h:
#import <UIKit/UIKit.h>
@protocol SubviewProtocol<NSObject>
- (void) textFieldDidEndEditing:(UITextField *)inTextField;
- (void) textFieldDidBeginEditing:(UITextField *)inTextField;
@end
@interface PopOverViewController : UIViewController <FPPopoverControllerDelegate>
@property (strong, nonatomic) UITextField *textField;
@property (nonatomic, assign) id<SubviewProtocol> delegate;
@end
Subview.m 中的 viewDidLoad :
textField = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 170, 30)];
textField.placeholder = @"Example";
textField.backgroundColor = [UIColor whiteColor];
textField.alpha = 0.9;
textField.borderStyle = UITextBorderStyleLine;
textField.layer.borderColor = [[UIColor grayColor]CGColor];
textField.textColor = [UIColor blackColor];
textField.delegate = self;
[self.view addSubview:textField];
NewImageViewController.m 中的委托方法:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"asd");
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"fgh");
}