Я нашел этот пример кода о том, как добавить текстовое поле для UIAlertController
, но я не могу ограничить пользователей вводом только 10 символов в качестве ограничения, у меня есть функция для удаления последнего символа при его переходе, когда редактирование изменено для обычного текстового поля, но невозможно проверить текстовое поле на UIAlertController
.
//Function to Remove the last character
func trimStr(existStr:String)->String{
var countExistTextChar = countElements(existStr)
if countExistTextChar > 10 {
var newStr = ""
newStr = existStr.substringToIndex(advance(existStr.startIndex,(countExistTextChar-1)))
return newStr
}else{
return existStr
}
}
var inputTextField: UITextField?
//Create the AlertController
let actionSheetController: UIAlertController = UIAlertController(title: "Alert", message: "Swiftly Now! Choose an option!", preferredStyle: .Alert)
//Create and add the Cancel action
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
//Do some stuff
}
actionSheetController.addAction(cancelAction)
//Create and an option action
let nextAction: UIAlertAction = UIAlertAction(title: "Next", style: .Default) { action -> Void in
}
actionSheetController.addAction(nextAction)
//Add a text field
**actionSheetController.addTextFieldWithConfigurationHandler { textField -> Void in
//TextField configuration
textField.textColor = UIColor.blueColor()
inputTextField = textField**
}
//Present the AlertController
self.presentViewController(actionSheetController, animated: true, completion: nil)
Спасибо.