Crashlytics中的EXC_BREAKPOINT 0x00000000e7ffdefe

时间:2016-08-24 14:52:58

标签: ios swift crashlytics twitter-fabric

我在Crashlytics中遇到以下错误

  

LoginViewController.swift第277行   LoginViewController.textField(的UITextField,   shouldChangeCharactersInRange:_NSRange,replacementString:String)    - >布尔

我的项目中有代码:

   // 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;
}

此错误有时只会出现

1 个答案:

答案 0 :(得分:2)

你强行解开你的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
}