【发布时间】:2009-11-17 10:00:22
【问题描述】:
self.delegate = self; 这样做有什么问题?
正确的做法是什么?
谢谢,尼尔。
代码:
(UITextField*)initWith:(id)sender:(float)X:(float)Y:(float)width:(float)hieght:(int)textFieldTag {
if (self = [super initWithFrame:CGRectMake(X, Y,width, hieght)]) {
finalText = [[NSMutableString alloc] initWithString:@""];
senderObject = sender;
self.textColor = [UIColor blackColor];
self.font = [UIFont systemFontOfSize:17.0];
self.backgroundColor = [UIColor whiteColor];
self.autocorrectionType = UITextAutocorrectionTypeNo;
self.keyboardType = UIKeyboardTypeDefault;
self.returnKeyType = UIReturnKeyDone;
self.clearButtonMode = UITextFieldViewModeWhileEditing;
self.tag = textFieldTag;
self.delegate = self;
[sender addSubview:self];
}
return self;
}
注意事项:这是一个文本字段,当我将委托设置为另一个对象(self.delegate = mainView)时,一切正常,但是我必须在mainView,我想把它们放在 self(我创建的一个 uiTextField 类)中。如果我设置 self.delegate = self,我会得到一个 textField 但键盘没有出现。
【问题讨论】:
-
请澄清:你为什么知道我错了。发生了什么
-
嗨。这是一个文本字段,当我将委托设置为另一个对象(self.delegate = mainView)时,一切正常,但是我必须在 mainView 中实现委托方法,我想将它们放入 self(我创建的 uiTextField 类)。如果我设置 self.delegate = self,我会得到一个 textField 但键盘没有显示。
-
在问题中添加了来自 OP 的评论。
-
UITextView 的独特之处在于无法做到这一点。解决方法很简单,stackoverflow.com/a/13338493/294884
标签: iphone uitextfield delegates self