Note that there are some explanatory texts on larger screens.

plurals
  1. POCan search within an object
    primarykey
    data
    text
    <p>I have a view with a tableview and a searchbar. My tableview is filled with data take to SQLite, now i would add a searchbar. Database fields are invoked through an object.</p> <p>Receip.h</p> <pre><code>@interface Receip : NSObject { int ID; //id receip NSString *name; NSString *ingredients; NSString *detail; NSString *image; } </code></pre> <p>While my SearcViewController is:</p> <pre><code>#import "Receip.h" #import "DBAccess.h" #import "SearchViewController.h" #import "DetailViewController.h" @implementation SearchViewController @synthesize table,search, dataSource, tableData; - (void)viewDidLoad { [super viewDidLoad]; //initialize the two arrays; dataSource will be initialized and populated tableData = [[NSMutableArray alloc]init]; dataSource = [[NSMutableArray alloc] init]; // DBAccess object DBAccess *dbAccess = [[DBAccess alloc] init]; // insert all recipes in the array dataSource = [dbAccess getAllRecipes]; if ([dataSource count] &gt; 0){ [tableData addObjectsFromArray:dataSource]; //on launch it should display all the records [table reloadData]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"cellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease]; } // Configure the cell. // Get the Receip object Receip *receip = [tableData objectAtIndex:indexPath.row]; cell.textLabel.text = receip.name; cell.textLabel.font = [UIFont boldSystemFontOfSize:15.0]; cell.textLabel.numberOfLines = 2; cell.detailTextLabel.text = receip.detail; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void) searchTableView { NSString *searchText = search.text; NSMutableArray *productArray = [[NSMutableArray alloc] init]; for (int i = 0; i &lt; [dataSource count]; i++) { Receip *receip = [dataSource objectAtIndex:i]; NSString* sTemp = receip.name; NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch]; if (titleResultsRange.length &gt; 0) [productArray addObject:product]; } [tableData release]; tableData = [[NSMutableArray alloc] initWithArray:productArray]; [productArray release]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ if([searchText length] &gt; 0) { searchFlag = YES; [self searchTableView]; } else { searchFlag = NO; } [table reloadData]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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