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 5961145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:55:27+00:00 2026-05-22T18:55:27+00:00

Can someone exlain this code in detail and suggest how I can sort on

  • 0

Can someone exlain this code in detail and suggest how I can sort on the name?

- (void)handleSearchForTerm:(NSString *)searchTerm {

selectButton.enabled = NO;

NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];

for (NSString *key in self.keys) {
    NSMutableArray *array = [Categories valueForKey:key];
    NSMutableArray *toRemove = [[NSMutableArray alloc] init];
    for (NSString *name in array) {
        if ([name rangeOfString:searchTerm 
                        options:NSCaseInsensitiveSearch].location == NSNotFound)
            [toRemove addObject:name];
    }

    if ([array count] == [toRemove count])
        [sectionsToRemove addObject:key];

    [array removeObjectsInArray:toRemove];
    [toRemove release];
}
[self.keys removeObjectsInArray:sectionsToRemove];
[sectionsToRemove release];
[table reloadData];
}
  • 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-05-22T18:55:28+00:00Added an answer on May 22, 2026 at 6:55 pm
    - (void)handleSearchForTerm:(NSString *)searchTerm {
      selectButton.enabled = NO;
      NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init]; //creating an mutable array, which can be altered in progress.
      [self resetSearch]; //calling some other method not displayed in the code here
      for (NSString *key in self.keys) { //for each key, 
         NSMutableArray *array = [Categories valueForKey:key];  //you get the key's category
         NSMutableArray *toRemove = [[NSMutableArray alloc] init]; //and initialize the array for items you wish to remove
         for (NSString *name in array) { //then, for each name
             if ([name rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location == NSNotFound)
                 [toRemove addObject:name];
                 //you check if the name is in range of the searchterm, with which you call this function
                 //if you don't find it, you add it to the removal list
         }
         if ([array count] == [toRemove count])
             [sectionsToRemove addObject:key]; //if you haven't found any name, it means you've added all the names in the toRemove array
         [array removeObjectsInArray:toRemove]; //that means the count of both arrays are the same    
         [toRemove release]; //so you remove that section entirely, since there is no result there
     }
     [self.keys removeObjectsInArray:sectionsToRemove]; //you remove all the keys which aren't found
     [sectionsToRemove release]; //leaving you the keys which are found
     [table reloadData]; //you reload the table with the found results only
    }
    

    I hope it all made sense, I did my best commenting it 😉

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please explain this piece of code? struct Class { boost::function<void()> member; };
Can someone take a look at this part of my code and tell me
can someone explain me the compilation error in this code: #include common.h typedef struct
Ho there, can someone explain how to make this code working?? <%@taglib uri=/struts-tags prefix=s%>
This little piece of code has been a staple in a bunch of my
Possible Duplicate: Use templates to get an array's size and end address Can someone
The python docs gives this code as the reverse operation of zip: >>> x2,
I am trying to understand a third party Javascript code. But am not able
I have an app that plays radio stations, and I now want to integrate
So, I've quantized a grayscale image with four quantized values. I'm trying to maintain

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.