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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:48:56+00:00 2026-06-17T06:48:56+00:00

I have a TableView with many rows, most are not visible at the time

  • 0

I have a TableView with many rows, most are not visible at the time of loading viewController. The rows of UITableView are extracted from a SQLite database. How can I make do that the SearchBar search between all rows and not just the visible ones?

In header file:

 @interface ExhibitorsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>{
BOOL isSearchOn;
BOOL canSelectRow;
NSMutableArray * listOfExpositors;
NSMutableArray * searchResult;

}

 //....
 @end

In implementation file

 -(NSInteger)tableView:(UITableView *)tableView
  numberOfRowsInSection:(NSInteger)section
{
     if(isSearchOn){
           return [searchResult count];
           //In this array there are the elements after use of searchBar
     }else{
          int number=[self.mutableArray count];
         //In this array there are all elements of database, extracts in viewDidLoad()
       return number;
     }
}

 - (UITableViewCell *)tableView:(UITableView *)aTableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {


       static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
         if (cell == nil) {
           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
           reuseIdentifier:CellIdentifier] ;
}

       if(isSearchOn){
            NSString * cellValue = [searchResult objectAtIndex:indexPath.row];
           cell.textLabel.text = cellValue;
      }else{
           //loading data from the database
           Database *currow =[self.mutableArray objectAtIndex:indexPath.row];

           cell.textLabel.text = currow.name;


         [listOfExpositors addObject:cell.textLabel.text];
         //here only loads the list of names visible and not the entire table
         //How do I put all the elements in this array?
         NSLog(@" %@", listOfExpositors);

         isSearchOn = NO;
         canSelectRow = YES;
  }
}




 -(void) doneSearching{
      isSearchOn = NO;
      canSelectRow = YES;
      self.tableView.scrollEnabled = YES;

     [self.searchBar resignFirstResponder];
     [self.tableView reloadData];

 }

  -(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
        isSearchOn = YES;
        if(self.searchBar.text.length>0){
            canSelectRow=YES;
            self.tableView.scrollEnabled = YES;
        }else{
            canSelectRow= NO;
            self.tableView.scrollEnabled = NO;

        }
    }

   -(void) searchExpositorsTableView{
         [searchResult removeAllObjects];

         for (NSString *str in listOfExpositors){


              NSRange titleResultsRange = [str rangeOfString:self.searchBar.text options:
               NSCaseInsensitiveSearch];;

              if (titleResultsRange.length >0) {
                      [searchResult addObject:str];

              }
          }
        NSLog(@"%@", searchResult);
      }

    -(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
             if([searchText length]>0){
                     canSelectRow = YES;
                     self.tableView.scrollEnabled = YES;
                     [self searchExpositorsTableView];
             }else{
                    canSelectRow = NO;
                    self.tableView.scrollEnabled = NO;


              }

             [self.tableView reloadData];
        }

      -(void) searchBarSearchButtonClicked:(UISearchBar *)searchBar{
            [self searchExpositorsTableView];
            [self.searchBar resignFirstResponder];
      }

   -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{

        if(canSelectRow){


            return indexPath;

        }else{
              return nil;
       }
      NSLog(@"%d", indexPath.row);
    }
  • 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-17T06:48:57+00:00Added an answer on June 17, 2026 at 6:48 am

    It was wrong to use the array created in cellForRowAtIndexPath because it was limited only to the visible elements. I then used the NSMutableArray created in viewDidLoad () that does contain all the elements of the database. I changed the following methods:

     - (UITableViewCell *)tableView:(UITableView *)aTableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        //....
    
       if(isSearchOn){
           NSString * cellValue = [searchResult objectAtIndex:indexPath.row];
           cell.textLabel.text = cellValue;
       }else{
          Database *currow =[self.mutableArray objectAtIndex:indexPath.row];
    
    
           cell.textLabel.text = currow.name;
    
         //Should be removed  this array and used to another, self.mutableArray
    
        //[listOfExpositors addObject:cell.textLabel.text];
        // NSLog(@" %@", listOfExpositors);
    
        isSearchOn = NO;
        canSelectRow = YES;
      }
    }
    

    Method for research

     -(void) searchExpositorsTableView{
          [searchResult removeAllObjects];
    
          for (Database *currow in self.mutableArray){ 
                 /*In self.mutableArray there are all elements because is created in
                   viewDidLoad*/
                 NSLog(@"list of expositors %@", self.mutableArray);
    
                 NSRange titleResultsRange = [currow.name rangeOfString:self.searchBar.text options: NSCaseInsensitiveSearch];
                 if (titleResultsRange.length >0) {
                      [searchResult addObject:currow.name];
    
                 }
            }
    
           NSLog(@"%@", searchResult);
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have TableView. My datasource is SQLite database. I'm trying to count a number
I have an UITableView with sections and many rows. I don't need a detailed
I have done many approach on changing font colors from a tableView cell. apparently
i have tableview with custom cell.the table is divided in many section and rows.i
I have a UITableView with many rows, each row contains a UIWebView. The content
I have a tableview, which has many sections. each section has just one cell.
I have tableview, where create new rows and set them layout manually. In every
I have a TableView with 10 sections that are loaded from a plist file
I have a TableView associated to a TreeView. Each time a node in the
I have a UITableview made up with a custom cell loaded from a nib.

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.