mos*_*ic6 18 ios nsrange swift
检查字符串字符的范围时出现此错误...
@objc func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let shouldChange = false
let text = textField.text
var newString = text!.stringByReplacingCharactersInRange(range, withString: string) as? NSString
if newString.length > 14{
newString = newString.substringToIndex(14)
}
textField.text = newString.uppercaseString
return shouldChange
}
Run Code Online (Sandbox Code Playgroud)
mat*_*att 34
而不是text!说(text! as NSString).
var newString = (text! as NSString).stringByReplacingCharactersInRange(range, withString: string) as? NSString
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9706 次 |
| 最近记录: |