UITextFIEld的委托等于self.委托方法textFIEldDIDBeginEditing和textFIEldDIDEndEditing执行textfIEld的背景突出显示效果.
接下来我在我的UIVIEwController中使用这个自定义UIVIEw(HCTextFIEldVIEw).要处理工具栏中的“下一个”和“上一个”按钮的 *** 作(附在文本字段的键盘上方),我需要在UIVIEwController中使用相同的文本字段的委托方法,但是委托被覆盖了.
**@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];}@H_419_4@解决方法 在HCBaseTextFIEld中设置委托就像
在HCBaseTextFIEld.h中添加一个属性
@property (nonatomic,assign) ID<UITextFIEldDelegate> textFIEldDelagate;
在HCBaseTextFIEld.m中
- (BOol)textFIEldShouldBeginEditing:(UITextFIEld *)textFIEld { .... if (self.textFIEldDelagate && [self.textFIEldDelagate respondsToSelector:@selector(textFIEldShouldBeginEditing:)]) { [self.textFIEldDelagate textFIEldShouldBeginEditing:textFIEld]; } return YES;}- (voID) textFIEldDIDBeginEditing:(UITextFIEld *)textFIEld { .... if (self.textFIEldDelagate && [self.textFIEldDelagate respondsToSelector:@selector(textFIEldDIDBeginEditing:)]) { [self.textFIEldDelagate textFIEldDIDBeginEditing:textFIEld]; }}... //Other delegate methods if needed
在VIEwController中:UIVIEwController
...HCTextFIEldVIEw *textFIEldVIEw = [[HCTExtFIEldVIEw alloc] init];textFIEldVIEw.textFIEldDelagate = self;...
并实现委托方法.
- (voID) textFIEldDIDBeginEditing:(UITextFIEld *)textFIEld { .... //Do the stuff}@H_419_4@ @H_419_4@ @H_419_4@ @H_419_4@ 总结
以上是内存溢出为你收集整理的ios – 同时在自定义UIView和UIViewController中使用相同的UITextFieldDelegate方法全部内容,希望文章能够帮你解决ios – 同时在自定义UIView和UIViewController中使用相同的UITextFieldDelegate方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)