首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下面的UITextChecker函数不能正常工作

下面的UITextChecker函数不能正常工作
EN

Stack Overflow用户
提问于 2013-07-08 20:55:04
回答 1查看 406关注 0票数 1
代码语言:javascript
复制
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这样的错误单词,请帮助我这背后的原因是什么。有没有其他选择来解决这个问题?

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-26 01:22:03

代码语言:javascript
复制
    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;

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17527200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档