@property (nonatomic, strong) NSArray *localGDBQueryResult;
-(void) localgeodatabaseSearchForValue:(NSString*)searchString { NSError *GDBError; AGSGDBGeodatabase *gdb = [AGSGDBGeodatabase geodatabaseWithName:@"mygeodb" error:&GDBError]; if (gdb) { AGSGDBFeatureTable *table = [gdb featureTableForLayerName:@"Mileposts"]; NSString *fieldname = @"MPOINT"; AGSQuery *query = [[AGSQuery alloc] init]; query.where = [NSString stringWithFormat:@"%@ = '%@'",fieldname, searchString]; [table queryResultsWithParameters:query completion:^(NSArray *results, NSError *error) { if (!error) { self.localGDBQueryResult = results; [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); } }]; } }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.localGDBQueryResult count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = [[self.localGDBQueryResult objectAtIndex:indexPath.row] valueForKey:@"RoadName"]; return cell; }
Solved! Go to Solution.
@property (nonatomic, strong) NSArray *queryArrayResults; @property (nonatomic, strong) AGSGDBFeatureTable *table;
-(void) localgeodatabaseSearchForValue:(NSString*)searchString { NSError *GDBError; AGSGDBGeodatabase *gdb = [AGSGDBGeodatabase geodatabaseWithName:@"mygeodb" error:&GDBError]; if (gdb) { self.table = [gdb featureTableForLayerName:self.segmentSelection]; NSString *fieldname = @"Mileposts"; AGSQuery *query = [[AGSQuery alloc] init]; query.where = [NSString stringWithFormat:@"%@ = '%@'",fieldname, searchString]; [self.table queryResultsWithParameters:query completion:^(NSArray *results, NSError *error) { if (!error) { NSArray *arr = results; NSMutableArray *mutArr = [[NSMutableArray alloc]init]; for (int i =0; i<[arr count]; i++) { AGSGDBFeature *feat =[arr objectAtIndex:i]; NSDictionary *dic = [[NSDictionary alloc] initWithDictionary:[feat allAttributes]]; [mutArr addObject:dic]; } self.queryArrayResults = [mutArr copy]; // reload the table [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); } }]; } }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.queryArrayResults count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = [[self.queryArrayResults objectAtIndex:indexPath.row] objectForKey:@"RoadName"]; return cell; }
AGSGDBFeatureTable *table = [gdb featureTableForLayerName:@"Mileposts"];
@property (nonatomic, strong) NSArray *queryArrayResults; @property (nonatomic, strong) AGSGDBFeatureTable *table;
-(void) localgeodatabaseSearchForValue:(NSString*)searchString { NSError *GDBError; AGSGDBGeodatabase *gdb = [AGSGDBGeodatabase geodatabaseWithName:@"mygeodb" error:&GDBError]; if (gdb) { self.table = [gdb featureTableForLayerName:self.segmentSelection]; NSString *fieldname = @"Mileposts"; AGSQuery *query = [[AGSQuery alloc] init]; query.where = [NSString stringWithFormat:@"%@ = '%@'",fieldname, searchString]; [self.table queryResultsWithParameters:query completion:^(NSArray *results, NSError *error) { if (!error) { NSArray *arr = results; NSMutableArray *mutArr = [[NSMutableArray alloc]init]; for (int i =0; i<[arr count]; i++) { AGSGDBFeature *feat =[arr objectAtIndex:i]; NSDictionary *dic = [[NSDictionary alloc] initWithDictionary:[feat allAttributes]]; [mutArr addObject:dic]; } self.queryArrayResults = [mutArr copy]; // reload the table [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); } }]; } }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.queryArrayResults count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = [[self.queryArrayResults objectAtIndex:indexPath.row] objectForKey:@"RoadName"]; return cell; }