Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
Ios 在自定义UIView和UIViewController中同时使用相同的UIExtFieldDelegate方法_Ios_Uitextfield_Appdelegate_Uitextfielddelegate - Fatal编程技术网

Ios 在自定义UIView和UIViewController中同时使用相同的UIExtFieldDelegate方法

Ios 在自定义UIView和UIViewController中同时使用相同的UIExtFieldDelegate方法,ios,uitextfield,appdelegate,uitextfielddelegate,Ios,Uitextfield,Appdelegate,Uitextfielddelegate,我有一个UIView(名为HCTextFieldView),其中包含子视图:UITextField和上面的UILabel UITextField的委托等于self。委托方法textfieldDiBeginediting和textFieldDidEndEditing执行textfield的背景突出显示效果 接下来,我将在我的UIViewController中使用此自定义UIView(HCTextFieldView)。若要处理工具栏中“下一步”和“上一步”按钮的操作(附加在textfield键盘上方

我有一个
UIView
(名为HCTextFieldView),其中包含子视图:
UITextField
和上面的
UILabel

UITextField的
委托等于self。委托方法
textfieldDiBeginediting
textFieldDidEndEditing
执行textfield的背景突出显示效果

接下来,我将在我的
UIViewController
中使用此自定义
UIView
(HCTextFieldView)。若要处理工具栏中“下一步”和“上一步”按钮的操作(附加在textfield键盘上方),我需要在
UIViewController
中使用相同的textfield委托方法,但委托被覆盖

**@interface HCBaseTextField : UIView <UITextFieldDelegate>**
...
@end

**@implementation HCBaseTextField {}**

...

textField = [[UITextField alloc] initWithFrame:CGRectMake(0, titleLabel.bottom, self.width - 20, self.height - titleLabel.height)];
**textField.delegate = self**;

...

#pragma mark - UITextField delegate

//textFieldBG - UIImageView that act as background

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    [textFieldBg setImage:[[UIImage imageWithName:@"btn_vvod_medium_act"] stretchableImageWithLeftCapWidth:10 topCapHeight:10]];
    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    [textFieldBg setImage:[[UIImage imageWithName:@"btn_vvod_medium_norm"] stretchableImageWithLeftCapWidth:10 topCapHeight:10]];
    return YES;
}

...

@end


**ViewController : UIViewController**

...

HCTextFieldView *textFieldView = [[HCTExtFieldView alloc] init];
textFieldView.textField.delegate = self;

...

//I need to use this methods too but they override previous in UIView delegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [self.keyboardControls setActiveField:textField];
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    [self.keyboardControls setActiveField:textView];
}
***接口HCBaseTextField:UIView**
...
@结束
**@实现HCBaseTextField{}**
...
textField=[[UITextField alloc]initWithFrame:CGRectMake(0,titleLabel.bottom,self.width-20,self.height-titleLabel.height)];
**textField.delegate=self**;
...
#pragma标记-UITextField委托
//textFieldBG-用作背景的UIImageView
-(BOOL)textField应该开始编辑:(UITextField*)textField{
[textFieldBg setImage:[[UIImage imageWithName:@“btn\U vvod\U medium\U act”]可拉伸图像,左顶宽:10顶顶高:10];
返回YES;
}
-(BOOL)textField应取消编辑:(UITextField*)textField{
[textFieldBg setImage:[[UIImage imageWithName:@“btn\U vvod\U medium\U norm”]LeftCapWidth:10 topCapHeight:10]可拉伸图像;
返回YES;
}
...
@结束
**ViewController:UIViewController**
...
HCTextFieldView*textFieldView=[[HCTextFieldView alloc]init];
textFieldView.textField.delegate=self;
...
//我也需要使用此方法,但它们会覆盖以前的UIView委托
-(无效)textFieldDidBeginEditing:(UITextField*)textField
{
[self.keyboardControls setActiveField:textField];
}
-(无效)textViewDidBeginEditing:(UITextView*)textView
{
[self.keyboardControls setActiveField:textView];
}

HCBaseTextField
中设置一个
委托

HCBaseTextField.h中添加属性

@property (nonatomic, assign) id<UITextFieldDelegate> textFieldDelagate;
视图控制器中:UIViewController

...

HCTextFieldView *textFieldView = [[HCTExtFieldView alloc] init];

textFieldView.textFieldDelagate = self;

...
并实现委托方法

- (void) textFieldDidBeginEditing:(UITextField *)textField {
    ....

    //Do the stuff
}
- (void) textFieldDidBeginEditing:(UITextField *)textField {
    ....

    //Do the stuff
}