2012-05-14 29 views
16

Tôi hiện đang sử dụng UIAlertView này để làm một tên đăng nhập popup,UIAlertView: UIAlertViewStyleSecureTextInput: Numeric Bàn phím

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Restricted" 
               message:@"Please Enter Code to Enable Fields" 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"Login" 
         , nil]; 
alert.alertViewStyle = UIAlertViewStyleSecureTextInput; 

[alert show]; 

Tuy nhiên tôi muốn đầu vào văn bản để trở thành một bàn phím số thay cho bàn phím thông thường

Có cách nào dễ dàng để thực hiện việc này hay tôi phải xem xét việc tạo UIAleartView tùy chỉnh

Trả lời

51

Bạn có thể thử cách này để thay đổi loại bàn phím của trường của UIAlertView:

[[alert textFieldAtIndex:0] setDelegate:self]; 
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad]; 
[[alert textFieldAtIndex:0] becomeFirstResponder]; 
+0

add để bạn * .h tập tin –

4

mát câu trả lời nhưng đối với iOS 7 Tôi có một chút thích ứng

alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
[alert show]; 
[[alert textFieldAtIndex:0] setDelegate:self]; 
[[alert textFieldAtIndex:0] resignFirstResponder]; 
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypePhonePad]; 
[[alert textFieldAtIndex:0] becomeFirstResponder]; 
+0

Thay đổi bàn phím trước khi gọi '[chương trình cảnh báo];' nên giảm bớt sự cần thiết phải từ chức và trở thành người trả lời đầu tiên. – rebello95

4
UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"Enter File Number" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; 
     alertView1.alertViewStyle = UIKeyboardTypePhonePad; 
     myTextField = [alertView1 textFieldAtIndex:0]; 
     myTextField.keyboardType=UIKeyboardTypeNumberPad; 
     [alertView1 setTag:3]; 
     [alertView1 show];