2014-03-13 31 views

回答

0

無法修改標準數字鍵盤。典型的解決方案是使用按鈕設置工具欄,並使該視圖成爲文本字段的inputAccessoryView。點擊按鈕後,您可以在文本框中調用resignFirstResponder

+0

@maddy工具欄顯示哪裏?我一直在使用pickerview作爲另一個項目中的inputAccessoryView,並且pickerview顯示的不是textview的鍵盤。但我不需要帶按鈕而不是鍵盤的工具欄,我需要兩個顯示。你有沒有嘗試過? – mrd

+0

我想你的意思是你一直在使用'UIPickerView'作爲'inputView'。 'inputAccessoryView'顯示在鍵盤的頂部(或'inputView')。 – rmaddy

+0

對,我的錯,它是'inputView'。我一直在尋找我在互聯網上找到的一些例子,它們包含大量的代碼,只在數字鍵盤上顯示返回鍵。你有鏈接到一個簡短的例子嗎? – mrd

2

你可以這樣做,你可以設置你自己的工具欄的位置。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    if(textField == yourTextField) 
    { 
     UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; 
     numberToolbar.barStyle = UIBarStyleBlackTranslucent; 
     numberToolbar.items = [NSArray arrayWithObjects: 
           [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
           [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
           [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButton)],nil]; 
     textField.inputAccessoryView = numberToolbar; 
} 
} 

- (void)doneButton 
{ 
    [youtTextField resignFirstResponder]; 
}