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

  • SEARCH
  • Home
  • 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 6845837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:32:59+00:00 2026-05-27T00:32:59+00:00

I have a search bar, i can search now, but when I enter a

  • 0

I have a search bar, i can search now, but when I enter a text to search, and click the cancel button. It does not give me back my first stage, meaning full of the items in the table.

For example: I search the item with word: a, it gives me all the a items, yes, it is right now, but when i hit the cancel button, i want the programme gives me all the items exist, not just a items.

Here is the code: please help me out. Thank you so much.

- (void)searchBarCancelButtonClicked:(UISearchBar *)aSearchBar
{
    searchBar.text = @"";
    [searchBar resignFirstResponder];

    letUserSelectRow = YES;
    searching = NO;
    self.tableView.scrollEnabled = YES;

    NSLog(@"what text after cancel now: %@", searchBar.text);

    [self.tableView reloadData];


}
- (NSMutableArray *) searchTableView {

    NSString *searchText = searchBar.text;
    NSLog(@"search text: %@", searchText);
    NSMutableArray *resultArray = [[NSMutableArray alloc] init];
    NSMutableArray *tempArr = [[NSMutableArray alloc] init];

    for (NSDictionary *dTemp in arrayData)
    {
        NSString *tempStr = [dTemp objectForKey:@"url"];
        NSLog(@"sTemp string: %@",[ NSString stringWithFormat:@"%@", tempStr]);
        NSRange titleResultsRange = [tempStr rangeOfString:searchText options:NSCaseInsensitiveSearch];

        if (titleResultsRange.length > 0)
        {
            NSLog(@"1 count :%d", [resultArray count]);
            [resultArray addObject:dTemp];
            NSLog(@"2 count :%d", [resultArray count]);
            [tempArr addObject:resultArray];
            [resultArray release];

            resultArray = [NSMutableArray new];
        }

    }
    if (resultArray != nil) {
        [resultArray release];
    }


    return tempArr;
}

- (void)searchBar:(UISearchBar *)aSearchBar textDidChange:(NSString *)searchText
{

    NSLog(@"what text after cancel now: %@", searchBar.text);

    if([searchText length] > 0) {
        [sortedArray removeAllObjects];
        searching = YES;
        letUserSelectRow = YES;
        self.tableView.scrollEnabled = YES;
        NSMutableArray *searchArray = [self searchTableView];
        sortedArray = [[NSMutableArray alloc] initWithArray:searchArray copyItems:YES];

        for (int i = 0; i<[sortedArray count]; i++) {
            NSLog(@"this is the search array: %@", [[sortedArray objectAtIndex:i] class]);
        }

        NSLog(@"sorted array: %d", [sortedArray count]);
    }
    else {

        searching = NO;
        letUserSelectRow = NO;
        self.tableView.scrollEnabled = NO;
    }

    [self.tableView 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-27T00:33:00+00:00Added an answer on May 27, 2026 at 12:33 am

    You don’t need to override any of UISearchBar methods to accomplish this. The new way of doing this relies on the UISearchDisplay controller instead (specifically on shouldReloadTableForSearchString).

    Declare your view controller to conform to UISearchDisplayDelegate protocol, and keep two instance variables: your model as NSArray (all data) and a filtered array as NSMutableArray (a subset of your data). The code you presently have in “searchTableView” would filter the content of the model and place it into the filtered NSMutableArray. Then you would override the following UITableView methods: -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section and -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath. In each, before returning, make a comparison to determine whether your tableView argument is equal to self.searchDisplayController.searchResultsTableView. If it is, the user is looking at the filtered list and your should use the content of the filtered NSMutableArray to create the view, otherwise, the user is looking at the whole data set and you should use the content of the NSArray that holds your model. Take a look at the following Apple code for a simple example of what I described:

    http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html

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

Sidebar

Related Questions

I have a tableview with a search bar. All is working fine but now
I have a tab bar and a search button on its toolbar. So now
I have a search bar. Entering text in it and clicking search takes you
alt text http://img216.imageshack.us/img216/2288/problem11.png As given in the picture, I have an search bar in
I have an application you can use below but basically it is a text
I have created a search bar for my website, the user may search a
I have a UI table view with a search bar and it works well
I have a Controller with a search bar at top, and when the user
I Have site change.is, where right side menu & search bar in header is
I have search through the web to figure this out but no luck. I

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.