簡體   English   中英

調用becomeFirstResponder后不調用shouldChangeCharactersInRange方法

[英]shouldChangeCharactersInRange method not called after calling becomeFirstResponder

嗨,我是iOS新手,

我在我的項目中使用了幾個文本字段,因此我想使用becomeFirstResponder對任何一個文本字段進行編輯。 它在xcode 3.2.5中工作正常,但它在xcode 4.2.1中出現問題

xcode 4.2.1中,在調用了becomeFirstResponder后,我無法編輯文本字段,它顯示的是虛擬鍵盤,我可以點擊鍵,但是在文本字段中沒有輸入敲擊的鍵。

請幫幫我。

首先在界面中添加此委托:

 @interface yourViewController : UIViewController<UITextFieldDelegate>

如果從xib使用,則右鍵單擊UITextField並使用fileowner綁定委托,否則在viewDidLoad的方法中添加此代碼。

  yourTextField.delegate = self;

添加UITextField的委托,它將被調用

 - (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;
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM