Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 有没有一种方法可以使用UITextChecker不区分大小写?_Ios_Nsstring - Fatal编程技术网

Ios 有没有一种方法可以使用UITextChecker不区分大小写?

Ios 有没有一种方法可以使用UITextChecker不区分大小写?,ios,nsstring,Ios,Nsstring,我需要我的应用程序来检查用户输入的单词是否是真单词。为此,我找到了UITextChecker。我用它来检查这样的词: UITextChecker *textChecker = [[UITextChecker alloc] init]; NSLocale *locale = [NSLocale currentLocale]; NSString *language = [locale objectForKey:NSLocaleLanguageCode]; NSRange searchRange =

我需要我的应用程序来检查用户输入的单词是否是真单词。为此,我找到了UITextChecker。我用它来检查这样的词:

UITextChecker *textChecker = [[UITextChecker alloc] init];
NSLocale *locale = [NSLocale currentLocale];
NSString *language = [locale objectForKey:NSLocaleLanguageCode];
NSRange searchRange = NSMakeRange(0, [currentWord length]);

NSRange misspelledRange = [textChecker rangeOfMisspelledWordInString:currentWord range: searchRange startingAt:0 wrap:NO language:language];
if (misspelledRange.location == NSNotFound) NSLog(@"is a word");
else NSLog(@"is not a word");
这在以大写字母开头的单词(在德语中有很多单词:)之前都很有效。用户输入的文本是小写的,因此即使一个单词实际上是一个单词,它也会输出“不是一个单词”,因为它是小写的。 我在文档中没有找到这个问题的解决方案,我也在这里搜索了它。 因此,我的问题是,如果检查失败,是否有比将第一个字母转换为大写更好的方法

如果没有其他方法,我会怎么做:

NSRange misspelledRange = [textChecker rangeOfMisspelledWordInString:currentWord range: searchRange startingAt:0 wrap:NO language:language];
if (misspelledRange.location == NSNotFound) NSLog(@"is a word");
else {
    NSString *firstLetter = [currentWord substringToIndex:1];
    NSString *restWord = [currentWord substringFromIndex:1];

    currentWord = [NSString stringWithFormat:@"%@%@", [firstLetter capitalizedString], restWord];

    NSRange misspelledRange = [textChecker rangeOfMisspelledWordInString:currentWord range: searchRange startingAt:0 wrap:NO language:language];
    if (misspelledRange.location == NSNotFound) NSLog(@"is a word");
    NSLog(@"is not a word");
}
谢谢你的帮助