Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:59:55+00:00 2026-06-05T06:59:55+00:00

I am implementing a list that can be filtered with the text from a

  • 0

I am implementing a list that can be filtered with the text from a UITextField, with the help of a UITextFieldDelegate.

The code is the following:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

    _tempWrittenText = [textField.text stringByReplacingCharactersInRange: range withString: string];
    [self filterCountries];

    return YES;
}

/** Filter the countries with the currently typed text */
- (void) filterCountries {
    if (_tempWrittenText.length == 0) {
        _visibleCountriesList = (NSMutableArray*) _countriesList;
        [tableMedals reloadSections: [NSIndexSet indexSetWithIndex: 0] withRowAnimation: UITableViewRowAnimationNone];

    } else {
        _visibleCountriesList = [NSMutableArray array];

        for (Country* c in _countriesList) {
            if ([c.name rangeOfString: _tempWrittenText].location != NSNotFound) {
                [_visibleCountriesList addObject: c];
            }
        }
        [tableMedals reloadSections: [NSIndexSet indexSetWithIndex: 0] withRowAnimation: UITableViewRowAnimationFade];
    }

}

The filter works perfectly when typing on text; however, the - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string method is also fired when the DONE keyboard key is pressed (to hide the keyboard), which weirdly erases all items instead of leaving them as they are.

The issue is that the rangeOfString part is ALWAYS returning NSNotFound. I can’t understand why, if I log the variables the two strings are correct.

For example:
[@"Angola" rangeOfString @"A"].location will give NSNotFound

And I repeat, this only happens when the keyboard is hidden. Anyone has an Idea?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:59:57+00:00Added an answer on June 5, 2026 at 6:59 am

    The

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    

    is not fired when done button is pressed, otherwise if you force to call this function.

    Use this to hide the keyboard, this will not trigger above method.

    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        [textField resignFirstResponder];
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder, if I can inject a list of (stateless) beans, that all implementing
Situation: I'm implementing a list-like container that supports a Pop() function that should return
I am implementing iPhone app where I want to fetch list of friends from
I was in need of a little math help that I can't seem to
I have the following classes: Defect - represents a type of data that can
I'm trying to figure out a good way of implementing a List(Of) that holds
I'm having trouble implementing a QListWidget with custom items that can be reordered by
I have some problems in implementing a list view with 3 items, one text,
I need some help in implementing jQuery. I have a dropdown list with the
I am implementing a custom list definition that contains several columns. A requirement to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.