Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading Data in a Table View Controller
    primarykey
    data
    text
    <p>I have a table view in an iOS application I'm working on, and I want to load the data and start searching only when the search key on the keyboard is clicked. Presently, it loads the data when I start typing in the search field, however, since there is a lot of data, this creates a lot of lag. </p> <p>I've tried looking online, but most tutorials or examples refer to loading the data immediately or when the user is typing in the search bar. </p> <p>Any suggestions would be much appreciated, thank you!</p> <h2>UPDATE: SOLVED</h2> <p><em><strong>[Thanks to Tim &amp; channi's suggestions]</em></strong> </p> <p>The code below is the updated solution: </p> <pre><code>- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { /* loads the file into a dictionary */ NSString *myFile=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"]; dict = [[NSDictionary alloc] initWithContentsOfFile:myFile]; recipes = [dict allKeys]; NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", searchText]; searchResults = [recipes filteredArrayUsingPredicate:resultPredicate]; } -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [self filterContentForSearchText:self.searchBar.text scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; /* reloads the searchResults table view with the new data */ [self.searchDisplayController.searchResultsTableView reloadData]; [self.searchBar resignFirstResponder]; } -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { /* Sets both arrays to nil so main table view is a clean view */ searchResults = nil; recipes = nil; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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