我在 Crashlytics 中收到以下错误
LoginViewController.swift line 277 LoginViewController.textField(UITextField, shouldChangeCharactersInRange : _NSRange, replacementString : String) -> Bool
我的项目中有代码:
// MARK: - UITextFieldDelegate
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if textField == txtSearch && string != "\n"{
var substring: String = textField.text!
substring = (substring as NSString).stringByReplacingCharactersInRange(range, withString: string)
self.searchAutocompleteEntriesWithSubstring(substring)
}
return true;
}
此错误仅有时发生
最佳答案
您正在强制解开您的 textField.text!
,它可能为零。尝试下面的代码:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if textField == txtSearch && string != "\n"{
if let text = textField.text {
let substring = (text as NSString).stringByReplacingCharactersInRange(range, withString: string)
self.searchAutocompleteEntriesWithSubstring(substring)
}
}
return true
}
关于ios - Crashlytics 中的 EXC_BREAKPOINT 0x00000000e7ffdefe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39126697/