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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:38:47+00:00 2026-05-22T20:38:47+00:00

I am creating a searchbar in a tableview but I have problems with this

  • 0

I am creating a searchbar in a tableview but I have problems with this method delegate because I fill the table view with array inside another array…I show my code:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
ProgramAppDelegate *appDelegate = (ProgramAppDelegate *)[[UIApplication sharedApplication] delegate];
[tableData removeAllObjects];// remove all data that belongs to previous search
if([searchText isEqualToString:@""] || searchText==nil){
    [myTableView reloadData];
    return;
}
NSInteger counter = 0;
for(NSString *name in appDelegate.globalArray )
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
    NSRange r = [name rangeOfString:searchText];
    if(r.location != NSNotFound)
    {
        if(r.location== 0)//that is we are checking only the start of the names.
        {
            [tableData addObject:name];
        }
    }
    counter++;
    [pool release];
}
[myTableView reloadData];
}

You can see the code “for(NSString *name in appDelegate.globalArray )” it don’t work because I fill the table view with elements of arrays inside this global array, I make an example

In a row of my table view there is a uitableviewcell and inside it there are four label;
I write these label with string of this globalArray but in this way:

[cell.label1 setText:[[appDelegate.globalArray objectAtIndex:indexPath.row]objectAtIndex:1]];
[cell.label2 setText:[[appDelegate.globalArray objectAtIndex:indexPath.row]objectAtIndex:2]];
[cell.label3 setText:[[appDelegate.globalArray objectAtIndex:indexPath.row]objectAtIndex:3]];
[cell.label4 setText:[[appDelegate.globalArray objectAtIndex:indexPath.row]objectAtIndex:4]];

then in delegate method for searchbar the code “for(NSString *name in appDelegate.globalArray )” don’t work, How can I change my code?

** I DON’T SAY THAT I WANT TO CHECK ONLY LABEL1 FOR THE SEARCH

  • 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-22T20:38:48+00:00Added an answer on May 22, 2026 at 8:38 pm

    The problem here is that globalArray is an array of arrays. So the loop should be something like.

    for(NSArray *rowArray in appDelegate.globalArray )
    {
        for ( NSString *name in rowArray ) {
            // Do your processing here..
        }
    }
    

    Using tableData

    In your tableView:cellForRowAtIndexPath:, do this

    [cell.label1 setText:[[tableData objectAtIndex:indexPath.row]objectAtIndex:1]];
    [cell.label2 setText:[[tableData objectAtIndex:indexPath.row]objectAtIndex:2]];
    [cell.label3 setText:[[tableData objectAtIndex:indexPath.row]objectAtIndex:3]];
    [cell.label4 setText:[[tableData objectAtIndex:indexPath.row]objectAtIndex:4]];
    

    In your numberOfSectionsInTableView:, return 1;

    In your tableView:numberOfRowsInSection:, return [tableData count];

    You should include a method that will reset the search data to the original content when the user stops searching.

    - (void)resetSearchData {
        // Get appDelegate first.
    
        self.tableData = [NSArray arrayWithArray:appDelegate.globalArray];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating servlet that implements contextInitializer interface in this code, then accessing file inside contextinitialized()
i am creating the search bar and table view programatically using the following code
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
When creating a web application, and lets say you have a User object denoting
I currently this piece of code for creating a UISearchBar (adapted from a previous
I am creating an iPhone app which I would like to have a similar
I have a code like this Map<String, List> searchMap = new HashMap<String, List>(); for(int
Creating an installer for possible remote systems so that if they do not have

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.