JohnWickham
JohnWickham

Reputation: 561

'Search' label text with UITextField

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?

Upvotes: 0

Views: 163

Answers (1)

user529758
user529758

Reputation:

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

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

Upvotes: 0

Related Questions