我发现有关此示例代码如何添加文本框的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 …
Run Code Online (Sandbox Code Playgroud)