我修改了空格代码以删除文本字段输入中的空格,但这是一个问题,在模拟器上它工作正常并删除空格但在设备上,它根本不起作用我的代码:< / p>
var number = numberTxtField.text
if number!.hasPrefix("+98") {
let start = number!.index(number!.startIndex, offsetBy: 0);
let end = number!.index(number!.startIndex, offsetBy: 3);
number!.replaceSubrange(start..<end, with: "0")
self.trimmed = number!.replacingOccurrences(of: " ", with: "")
print(self.trimmed)
let pattern = "^[0-9]+$"
let predicate = NSPredicate(format: "self MATCHES [c] %@", pattern)
if predicate.evaluate(with: self.trimmed) {
print("Valid")
if self.trimmed == nil && self.trimmed == "" {
return
}
numberTxtField.resignFirstResponder()
self.view.endEditing(true)
SendNumber()
}
}
当我在模拟器上输入+98 912 123 1234
时,它会返回09121231234
,当我在设备上执行此操作时,它会返回0 912 123 1234
。
有谁知道为什么?