这是我的代码..我不知道我哪里坏了... 我用Swift语言对此进行编码,我想实现自动校正,我正在使用UITextChecker,但是当我按空格键时键盘崩溃... 帮我!! :'(
@IBAction func spacePressed(button: UIButton) {
(textDocumentProxy as UIKeyInput).insertText(" ")
let myString = (self.textDocumentProxy as? UITextDocumentProxy)?.documentContextBeforeInput
let textAsNSString = myString! as NSString
var checker:UITextChecker = UITextChecker()
var textLength = countElements(myString!)
var checkRange:NSRange = NSMakeRange(0, textLength)
var misspelledRange:NSRange = checker.rangeOfMisspelledWordInString(myString!, range: checkRange, startingAt: checkRange.location, wrap: false, language: "it_IT")
var arrGuessed:NSArray = checker.guessesForWordRange(misspelledRange, inString: textAsNSString, language: "it_IT")!
var correctedStr = textAsNSString.stringByReplacingCharactersInRange(misspelledRange, withString: arrGuessed.objectAtIndex(0) as String)
}