Filter fields using AGSPopupInfo fieldsinfos throws error

830
3
08-12-2011 08:01 AM
DarrenMackiewicz
Occasional Contributor
Does anyone know how to properly filter the list of fields to display in the PopupInfo?

Here is the code that sends all fields in the Feature Class off to the popupViewController


-(void)mapView:(AGSMapView *)mapView didClickCalloutAccessoryButtonForGraphic:(AGSGraphic *)graphic{
   

    self.popupInfo = [AGSPopupInfo popupInfoForGraphic: graphic];
   
    self.popupInfo.allowEditGeometry = NO;
   
    //Show popup for the graphic because the user tapped on the callout accessory button
    self.popupVC = [[[AGSPopupsContainerViewController alloc] initWithPopupInfo:_popupInfo graphic:graphic usingNavigationControllerStack:NO] autorelease];
    self.popupVC.delegate = self;
    self.popupVC.modalTransitionStyle =  UIModalTransitionStyleFlipHorizontal;
    //If iPad, use a modal presentation style
    if([[UIDevice currentDevice] isIPad])
        self.popupVC.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentModalViewController:self.popupVC animated:YES];
    [self.popupVC startEditingCurrentPopup];

}

I want to only show Two fields, instead of all of the fields in the Feature Service Feature Class that "graphic" represents.


The class reference is here: (Search for AGSPopupInfo)
http://help.arcgis.com/en/arcgismobile/10.0/apis/iOS/2.0/reference/index.html

It says to set the description to nil and then send it an NSArray of fields.
I try that, but get an error (see below for error).


-(void)mapView:(AGSMapView *)mapView didClickCalloutAccessoryButtonForGraphic:(AGSGraphic *)graphic{
   

    self.popupInfo = [AGSPopupInfo popupInfoForGraphic: graphic];
   
    self.popupInfo.allowEditGeometry = NO;


    NSMutableArray *items = [[NSMutableArray alloc] init];
   
    [items addObject:@"OBJECTID"];
    [items addObject:@"STATUS"];
   
    self.popupInfo.description = nil;
   
   self.popupInfo.fieldInfos = items;
   
    [items release];


   
    //Show popup for the graphic because the user tapped on the callout accessory button
    self.popupVC = [[[AGSPopupsContainerViewController alloc] initWithPopupInfo:_popupInfo graphic:graphic usingNavigationControllerStack:NO] autorelease];
    self.popupVC.delegate = self;
    self.popupVC.modalTransitionStyle =  UIModalTransitionStyleFlipHorizontal;
    //If iPad, use a modal presentation style
    if([[UIDevice currentDevice] isIPad])
        self.popupVC.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentModalViewController:self.popupVC animated:YES];
    [self.popupVC startEditingCurrentPopup];
}

When I run this, I get the following error:

2011-08-12 11:52:04.891 FeatureLayerEditingSample[16177:207] -[NSCFString isVisible]: unrecognized selector sent to instance 0x60f5c4
2011-08-12 11:52:04.940 FeatureLayerEditingSample[16177:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString isVisible]: unrecognized selector sent to instance 0x60f5c4'


Any ideas?
0 Kudos
3 Replies
DiveshGoyal
Esri Regular Contributor
There are a couple of ways.

1. You can tweak the feature layer such that it only brings down OBJECTID & STATUS fields. Then, when a popup is created for a  graphic in this layer, it will only display information for these fields.

featureLayer.outFields = [NSArray arrayWithObjects:@"OBJECTID", @"STATUS", @"Shape" nil];


2. The feature layer can continue to bring down all the fields from the server, but you will need to dig into the AGSPopupInfo that is created for a graphic of this layer, and remove the metadata related to fields you don't want to display.

AGSPopupInfo* info = [AGSPopupInfo popupInfoForGraphic:graphic];
    
    //Filter the fields we want to display to the user
    NSMutableArray* fieldInfos = [info.fieldInfos mutableCopy];
    NSMutableArray* displayWorthyFields = [[[NSMutableArray alloc] init] autorelease];
    
    for (AGSPopupFieldInfo* fieldInfo in fieldInfos) {
        if([fieldInfo.fieldName isEqualToString:@"STATUS"] ){
            [displayWorthyFields addObject:fieldInfo];
        }
    }
    
    info.fieldInfos = displayWorthyFields;


Note, we explicitly filter out the OBJECTID field in a popup because we don't recommend displaying that to an end user.
0 Kudos
DarrenMackiewicz
Occasional Contributor
Thanks !! That did it (option 2).

You rock !
0 Kudos
hermancheah
New Contributor
hi
i am trying to modify the feature editing sample from arcgis for offline editing use.

for the example post above i see that it's possible to read the field from a feature layer . am i right?

my intention is to read the field needed after the template being selected.
i am currently only able to load the template selection but not able to load the field list to pop up be great if anyone can assist.


-(void)featureTypeViewController:(FeatureTypeViewController*) featureTypeViewController didSelectFeatureTemplate:(AGSFeatureTemplate*)template forFeatureLayer:(AGSFeatureLayer*)featureLayer{
    NSLog(@"didselectfeaturetype :TRUE");
   
        //set the active feature layer to the one we are going to edit
    self.activeFeatureLayer = featureLayer;
   
        //create a new feature based on the template
    _newFeature = [self.activeFeatureLayer createFeatureWithTemplate:template];
   
        //Add the new feature to the feature layer's graphic collection
        //This is important because then the popup view controller will be able to
        //find the feature layer associated with the graphic and inspect the field metadata
        //such as domains, subtypes, data type, length, etc
        //Also note, if the user cancels before saving the new feature to the server,
        //we will manually need to remove this
        //feature from the feature layer (see implementation for popupsContainer:didCancelEditingGraphicForPopup: below)
    [self.activeFeatureLayer addGraphic:_newFeature];
   
        //Iniitalize a popup view controller
        // self.popupVC = [[[AGSPopupsContainerViewController alloc] initWithWebMap:self.webmap forFeature:_newFeature usingNavigationControllerStack:NO] autorelease];
    AGSPopupInfo* info = [AGSPopupInfo popupInfoForGraphic:_newFeature];

    info.allowEditGeometry = NO;
   
    NSMutableArray* fieldInfos = [info.fieldInfos mutableCopy];
    NSMutableArray* displayWorthyFields = [[[NSMutableArray alloc] init] autorelease];
   
    for (AGSPopupFieldInfo* fieldInfo in fieldInfos) {
        if([fieldInfo.fieldName isEqualToString:@"OBJECTID"] ){
            [displayWorthyFields addObject:fieldInfo];
        }
    }
   
    info.fieldInfos = displayWorthyFields;
   
   
    self.popupVC=[[[AGSPopupsContainerViewController alloc] initWithPopupInfo:info forFeature:_newFeature usingNavigationControllerStack:NO] autorelease];
   
   
    self.popupVC.delegate = self;
   
        //Only for iPad, set presentation style to Form sheet
        //We don't want it to cover the entire screen
    if([[UIDevice currentDevice] isIPad])
        self.popupVC.modalPresentationStyle = UIModalPresentationFormSheet;
   
        //Animate by flipping horizontally
    self.popupVC.modalTransitionStyle =  UIModalTransitionStyleFlipHorizontal;
   
        //First, dismiss the Feature Template Picker
    [self dismissModalViewControllerAnimated:YES];
   
        //Next, Present the popup view controller //ERROR HERE
    [self presentModalViewController:self.popupVC animated:YES];
    [self.popupVC startEditingCurrentPopup];
   
}
0 Kudos