UITextfieldでアラートを表示していますが、そのデリゲートメソッドが呼び出されません。私が何をしているかも間違っている。テキストフィールドでアラートを表示するには、以下のコードを使用しています。 UITextFieldデリゲートメソッドが呼び出されない
func takePasscodeToEnableTouch(){
self.passcodeInputOperationType = .EnableTouchID
alertControllerPassCodeEntry = UIAlertController(title: "", message: "Enter Passcode to enable the Touch Id.", preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (action) -> Void in
}
alertControllerPassCodeEntry!.addAction(cancelAction)
alertControllerPassCodeEntry!.addTextFieldWithConfigurationHandler { (txtField) -> Void in
txtField.placeholder = "Enter passcode"
txtField.delegate = self
txtField.tag = TextFieldTag.EnterPassCode
txtField.keyboardType = UIKeyboardType.NumbersAndPunctuation
txtField.accessibilityIdentifier = "PassCode"
txtField.secureTextEntry = true
txtField.addTarget(self, action:"textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged)
}
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController?.presentViewController(alertControllerPassCodeEntry!, animated: true, completion: nil)
}
とTextFieldのデリゲートメソッドは、次のとおりです。
func textFieldShouldBeginEditing(textField: UITextField) -> Bool
{
return true
}
func textFieldDidBeginEditing(textField: UITextField) // became first responder
{
}
func textFieldShouldEndEditing(textField: UITextField) -> Bool
{
return true
}
func textFieldDidEndEditing(textField: UITextField)
{
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
var isLimitExist: Bool
var accessIndentifier: String
if let str = textField.accessibilityIdentifier
{
accessIndentifier = str
}
else
{
accessIndentifier = ""
}
//checkFieldLimit function is used to check the limit of text and restrict
isLimitExist = UIUtils.checkFieldLimit(accessIndentifier, stringToMatch: textField.text!, rangeLength: range.length, stringLength: string.characters.count)
if !isLimitExist
{
return false
}
return true
}
テキストフィールドデリゲートメソッドはどこにありますか?あなたの質問を、呼び出されていないデリゲートメソッドで更新してください。 – rmaddy
あなたのコードにこれらの '! 'がすべて入っているのはなぜですか? – rmaddy
アラートコントローラの参照を保持しています。私はそれをオプションにしました。 –