2016-08-09 3 views
1

내 alertcontroller 코드는 다음과 같습니다 textfield.how에 입력 할 때 일반 키보드 대신 숫자 패드가 나타나게하고 싶습니다. ??alertcontroller 텍스트 필드 키보드를 숫자 패드로 변경하는 방법은 무엇입니까?

func addPasscodeAlert() 
{ 
    let blurEffect = UIBlurEffect(style: .Light) 
    let blurVisualEffectView = UIVisualEffectView(effect: blurEffect) 
    blurVisualEffectView.frame = view.bounds 
    self.view.addSubview(blurVisualEffectView) 

    let alertController = UIAlertController(title: "No passcode saved", message: "Please enter new 4 digit passcode.", preferredStyle: .Alert) 

    let defaultAction = UIAlertAction(title: "OK", style: .Cancel) { (action) -> Void in 


     if let textField = alertController.textFields?.first as UITextField? 
     { 
      textField.keyboardType = UIKeyboardType.NumberPad 
      self.passcode = textField.text! 
      let userDefaults = NSUserDefaults.standardUserDefaults() 
      userDefaults.setObject(self.passcode, forKey: "passcode") 
      self.showPasswordAlert() 
     } 
    } 

    alertController.addAction(defaultAction) 

    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in 

     textField.placeholder = "Password" 
     textField.secureTextEntry = true 
    } 
    self.presentViewController(alertController, animated: true, completion: nil) 
    blurVisualEffectView.removeFromSuperview() 


} 

답변

2

키보드 유형을 핸들러 방식으로 바꾸면 UIAlertAction이 아닙니다. 코드를 아래에서 바꾸십시오.

alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in 
    textField.keyboardType = UIKeyboardType.NumberPad 
    textField.placeholder = "Password" 
    textField.secureTextEntry = true 
}