'Search' label text with UITextField

巧了我就是萌 提交于 2019-12-12 03:43:30

问题


I've got a UILabel and a UITextField. Each time the user enters text in the field, I need to check weather the textfield text exists in the label's text (basically I'm searching the label's text) . I was using

NSRange range = [sentenceRequestLabel.text rangeOfString:resultString];
if (range.location == NSNotFound) {
    NSLog(@"string was found");
} else {
    NSLog(@"string was not found");
}

to check (resultString being the textfield.text), but even if the label text in the text field is not even close to the label's text NSLog says "string was found". Any ideas what's wrong?


回答1:


if (range.location == NSNotFound) {
    NSLog(@"string was found");

means "If string was not found, then print it was found". That == should be a !=.



来源:https://stackoverflow.com/questions/12221901/search-label-text-with-uitextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!