Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView scroll is never end after search
    text
    copied!<p>I have UITableView to show whole bunch of words from array. </p> <p>I also provide search bar on top of table view so when people type a word in textbox search then my code start filtering data from array.</p> <p>My result is good but my scroll in tableview is never end even though there is only one row. My tableview result can scroll down and down without no row.</p> <p>I don't know what going on with my table view.</p> <p>My code that I have implement.</p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if(self.tableView == tableView){ return [self.alphabet count]; }else{ return 1; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (self.tableView == tableView) { return [[self.vocabularyInfo objectAtIndex:section] count]; }else{ return [self.filteredVocabs count]; } } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [self.alphabet objectAtIndex:section]; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { if(self.tableView == tableView){ return self.alphabet; }else{ return nil; } } </code></pre> <p>// Display cell</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"CommentTableCell"; //-- try to get a reusable cell -- CommentTableCell *cell = (CommentTableCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; //-- create new cell if no reusable cell is available -- if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier owner:self options:nil]; cell = [nib objectAtIndex:0]; } VocabularyController *vc; // Display word from database else display vocabulary when searching if (tableView != self.searchDisplayController.searchResultsTableView) { vc = [self.vocabularyInfo[indexPath.section] objectAtIndex:indexPath.row]; }else{ vc = [self.filteredVocabs objectAtIndex:indexPath.row]; } cell.nameLabel.text = vc.korean; return cell; } </code></pre> <p>// My method that I used for filtering my array to display the result</p> <pre><code>- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{ if (searchString.length &gt; 0) { NSArray *vocabToSearch = self.vocabularyInfo; if (self.currentSearchString.length &gt; 0 &amp;&amp; [searchString rangeOfString:self.currentSearchString].location == 0) { vocabToSearch = self.filteredVocabs; } NSPredicate *predicate = [NSPredicate predicateWithFormat:@"korean CONTAINS[cd] %@", searchString]; self.filteredVocabs = [vocabToSearch filteredArrayUsingPredicate:predicate]; } else { self.filteredVocabs = self.vocabularyInfo; } self.currentSearchString = searchString; return YES; } </code></pre> <p>Please help me!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload