小编use*_*557的帖子

当用户使用swift键入时,限制UIAlertController中文本字段的输入?

我发现有关此示例代码如何添加文本框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)

ios swift uialertcontroller

6
推荐指数
1
解决办法
4953
查看次数

标签 统计

ios ×1

swift ×1

uialertcontroller ×1