0

I have a UITextField in my app and based on the user's input I want it to push to a specific view controller. right now my code is simply:

 if ([self.textField.text isEqualToString:@"tall"]) {
    [self.navigationController pushViewController:yesViewController animated:YES];
} 

however only if the user types in exactly "tall" it will work. I want to make it so that if he types "Jim is tall" is still performs the action. Basically I'm looking for a replacement for the method isEqualToString: and change it into containsString: which I can't seem to find. Any thoughts?

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
rivtracks
  • 43
  • 7

1 Answers1

3

Use rangeOfString::

if ([self.textField.text rangeOfString:@"tall"].location != NSNotFound) {
    // the text contains "tall"
}

Use rangeOfString:options: if you want to ignore case or other options:

if ([self.textField.text rangeOfString:@"tall" options:NSCaseInsensitiveSearch].location != NSNotFound) {
    // the text contains "tall"
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579