4

嗨,我是 iOS 新手,

我在我的项目中使用了几个文本字段,所以我想使用becomeFirstResponder对任何一个文本字段进行编辑。它在xcode 3.2.5中运行良好,但在xcode 4.2.1中出现问题

在调用becomeFirstResponder后的xcode 4.2.1中,我无法编辑文本字段,它显示虚拟键盘我可以点击按键,但点击的按键未输入到文本字段中。

请帮帮我。

4

1 回答 1

14

Firstly add this delegates in interface:

 @interface yourViewController : UIViewController<UITextFieldDelegate>

If using from xib then right click on UITextField and bind delegate with fileowner else add this code in viewDidLoad's method.

  yourTextField.delegate = self;

Add UITextField's delegate and it will be called

 - (BOOL)textFieldShouldReturn:(UITextField *)textField //resign first responder for textfield 
 {
    [textField resignFirstResponder];
    return YES;
 }

 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
 {
   return YES;
 }
于 2012-08-27T11:47:19.100 回答