我有3 UITextField
s动态给出,如下所示:
if(a isEqualtoString:@"1")
{
UITextField *t=[[UITextField alloc]initWithFrame:CGRectMake(20,20,20,20)];
t.text=s;
t.delegale=self;
[scroll addSubview:t];
}
if(a isEqualtoString:@"2")
{
UITextField *t=[[UITextField alloc]initWithFrame:CGRectMake(20,20,20,20)];
t.text=p;
t.delegale=self;
[scroll addSubview:t];
}
if(a isEqualtoString:@"3")
{
UITextField *t=[[UITextField alloc]initWithFrame:CGRectMake(20,20,20,20)];
t.text=r;
t.delegale=self;
[scroll addSubview:t];
}
我的问题出现在我编写didBeginEditing
errT.hidden=YES;
中
这是我的代码,但我无法编辑那些文本字段,而且我已经给了代理人.h
也。该怎么办?我尝试了许多没有帮助我的解决方案。帮帮我
更新:
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if(textField==t)
{
err.hidden=YES;
}
}
答案 0 :(得分:0)
试试这个::
if(a isEqualtoString:@"1")
{
....
t.text = @"s";
....
}
if(a isEqualtoString:@"2")
{
....
t.text = @"p";
....
}
if(a isEqualtoString:@"3")
{
....
t.text = @"r";
....
}
希望,它会帮助你。
答案 1 :(得分:0)
我不明白您的问题是否textFieldDidBeginEditing
未被调用。
如果是,请尝试这样做:如果“t”是在.m文件上创建的,则必须使用标记
进行跟踪t.tag = 1001;
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if(textField.tag == 1001) {
err.hidden=YES;
}
}
<强>更新强> 尝试设置所有属性并更改文本字段的名称(一些时间有效):
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20,20,20,20)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[self.scroll addSubview:textField];
您是否尝试将文本字段放在视图上? [self.view addSubview:textField];
有效吗?
答案 2 :(得分:0)
UITextField *t=[[[UITextField alloc]initWithFrame:CGRectMake(20,20,20,20)]autorelease];
t.delegale=self;
[scroll addSubview:t];
if(a isEqualtoString:@"1")
{
t.text=s;
}
if(a isEqualtoString:@"2")
{
t.text=p;
}
if(a isEqualtoString:@"3")
{
t.text=r;
}
// textfield的委托
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField canResignFirstResponder])
{
[textField resignFirstResponder];
}
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
// add your method here
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
}