1
NSString * currentWord;
        currentWord = Text.text;
        UITextChecker* checker = [[UITextChecker alloc] init];
        NSString* preferredLanguage = [[UITextChecker availableLanguages] objectAtIndex:0];
        NSRange range;
 range = [checker rangeOfMisspelledWordInString:currentWord
                                                 range:NSMakeRange(0, [currentWord length])
                                            startingAt:0
                                                  wrap:NO
                                              language:preferredLanguage];
        if (range.location == NSNotFound)
        {
            NSLog(@"Word found");
        }
        else
        {
            NSLog(@"Word not found");
        }

//这里我使用了UITextChecker函数,即使是错误的单词,上面的函数也会显示正确的单词语句,例如:abcd,bcde,cdef,CAPs这样的错误单词,请帮助我这是什么原因。有没有其他选择可以解决这个问题?

提前致谢

4

2 回答 2

2
    UITextChecker *Checker = [[UITextChecker alloc] init];

    NSRange range = NSMakeRange(0, inputWord.length);


    NSRange misspelledRange = [Checker rangeOfMisspelledWordInString:[Sentence lowercaseString] range:range startingAt:0 wrap:NO language:@"en_IN"];

    bool isValidWord = misspelledRange.location == NSNotFound;

    //NSLog(@"----%i", misspelledRange.location);
    if (isValidWord)
    {
        isValidWord = [self checkIfWordExistsInSuggestedSpellings:Sentence];
        NSLog(@"++++%d", isValidWord);

    }

    return isValidWord;

}
else
{
     NSLog(@"Invalid word");
    return false;

}
于 2013-09-25T17:22:02.643 回答
0

找到NS
表示没有找到您要求的任何内容。==是相等运算符。range.location当等于时,您的代码会打印“Word found” NSNotFound

于 2013-07-08T14:15:19.850 回答