2015-12-02 116 views
0

當我點擊此屏幕上提到的UITextField時,會出現一個小鍵盤鍵盤,問題是當我開始點擊數字時,我的UITextField不更新,只停留在沒有數字的情況下placeholder當輸入鍵盤按鍵時,UITextField不會更新

enter image description here

我需要做什麼?

感謝

添加代碼!

@IBOutlet weak var salarioTextField: UITextField! 

override func viewDidLoad() 

{ 
    super.viewDidLoad() 

    updateView() 

    salarioTextField.delegate = self 
} 

func textFieldShouldBeginEditing(textField: UITextField) -> Bool 

{ 

    if textField == feriasTextField 
    { 
     feriasTextField.inputView = feriasPicker 
    } 

    else if textField == salarioTextField 
    { 
     salarioTextField.keyboardType = UIKeyboardType.NumberPad 
    } 

    else if textField == inicioTextField 
    { 
     textField.inputView = datePicker 
     textField.inputAccessoryView = toolbar 
     datePicker.date = inicioDate 
    } 
    else if textField == motivoTextField 
    { 
     motivoTextField.inputView = motivoPicker 
    } 
    else 
    { 
     textField.inputView = datePicker 
     textField.inputAccessoryView = toolbar 
     datePicker.date = fimDate 
    } 
    return true 
} 

func textFieldDidBeginEditing(textField: UITextField) 
{ 
    backgroundScrollView.scrollEnabled = true 
    let scrollSize = CGSizeMake(view.frame.width, view.frame.height) 
    backgroundScrollView.contentSize = scrollSize 
    activeTextField = textField 
    activeTextField?.becomeFirstResponder() 
} 

func textFieldDidEndEditing(textField: UITextField) 
{ 
    backgroundScrollView.contentSize = CGSizeMake(0, 800) 
    backgroundScrollView.scrollEnabled = true 
} 

請忽略其他UITextField

+0

你爲textField設置了一個委託嗎? –

+0

添加你到目前爲止的代碼 –

+0

是的,我已經設置了委託。 –

回答

0

我剛想通了一下發生了什麼事。

我對以下方法返回false。

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { 
    return true; 

} 

只是改變它爲真,它的工作。 感謝您的幫助。

0

確保您已啓用該字段的用戶交互。

如果您實施委託方法textViewDidBeginEditing,則可以在此處放置斷點或print語句以查看是否觸發。

您可以嘗試在該字段中調用becomeFirstResponder

+0

我已經實現了委託方法,當我點擊這個'UITextField'時,它就成爲鍵盤出現的響應者廣告,但不起作用。 –

+0

您確定此字段的用戶互動功能已啓用? – Moonwalkr

+0

是的,我敢肯定... –