2013-03-22 105 views
1

在我的應用程序中,當我嘗試編輯(鍵入一些文本)UITextField時,光標只是閃爍,但除BACKSPACE外沒有任何字符被輸入(可能只有當我有一些初始文本時) ,返回和切換字符類型。無法編輯UITextField中的文本

我這是怎麼宣佈UITextField

txtmail =[[UITextField alloc]init]; 
      [txtmail setFrame:CGRectMake(288, 51,264, 31)]; 
      [txtmail setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtmail setText:[NSString stringWithFormat:@"%@",appDelegate.Email]]; 
      [txtmail setFont:[UIFont fontWithName:@"TimesNewRoman" size:14]]; 
      txtmail.textColor =[UIColor grayColor]; 
      txtmail.delegate=self; 
      [testScroll addSubview:txtmail]; 
在我.h文件中

我給這樣的

@interface pot: UIViewController<UITextFieldDelegate> 
{ 
    UITextField *txtmail; 
} 
+0

點擊文本字段時鍵盤會出現嗎? – 2013-03-22 05:12:45

+2

'[testScroll addSubview:txtemail];'有拼寫錯誤 – Dilip 2013-03-22 05:13:56

+0

你添加textmail或txtemail作爲子視圖是正確的嗎? – 2013-03-22 05:14:03

回答

2

只是你的這個類的方法代替這種方法,

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 

    return YES; 
}  
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ 

    return YES; 
} 
+0

@ user2197875讓我知道你使用上面的答案後得到什麼。 – 2013-03-22 06:19:37