2012-09-27 44 views
22

我想在用戶按下返回按鈕後將鍵盤類型從默認更改爲數字。 然而,設置keyboardType屬性後,什麼也沒有發生。以編程方式更改iOS上的鍵盤類型不做任何事情

我的代碼:

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; 

    return YES; 
} 

我已經給自己設定的文本字段委託,並按下返回按鈕後,該方法被調用。

編輯:由

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; 
    [textField reloadInputViews]; 
    return YES; 
} 
+0

http://stackoverflow.com/questions/7301018/programmatically-change-uitextfield-keyboard-type – Rushabh

+0

您可能要試試這個問題發佈的解決方案:http://stackoverflow.com/questions/1594346/dynamically-changing-keyboard-type-for-a-uisearchbar – henning77

回答

21

解決試試這個:

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; 
    [textField reloadInputViews]; 
    return YES; 
} 
+0

它幫助,謝謝! – Kladimir

+0

@Kladimir如果任何答案有幫助,並完全回答你的問題,你應該使用答案點和投票箭頭下方的正確符號將其標記爲已接受。 –

相關問題