2016-08-09 14 views
1

Gegeben unten ist der Code für meine alarmcontroller Ich möchte Numberpad anstelle der normalen Tastatur erscheinen, wenn ich in das Textfeld eintippe.wie dies zu tun?Wie ändere ich die Textfeld-Tastatur des Alarmcontrollers zu Numberpad?

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() 


} 

Antwort

2

Änderung Tastaturtyp in Handler-Methode nicht in UIAlertAction. Ersetzen Sie Ihren Code mit unten.

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