Adding callout (InfoTemplateDelegate) results in crash

1115
9
04-17-2012 06:35 AM
ReneNijkamp
New Contributor
Hi all,

I'm adding some graphics manually to the map, with the following code:

        double lat = [(NSNumber *) [colleague objectForKey: @"Latitude"] doubleValue];
        double lon = [(NSNumber *) [colleague objectForKey: @"Longitude"] doubleValue];
        
        if ( !(lat == 0.00 && lon == 0.00))
        { 
            AGSSimpleMarkerSymbol *pointMarker = [AGSSimpleMarkerSymbol simpleMarkerSymbolWithColor:[UIColor orangeColor]];
            pointMarker.size = 15; //[(NSNumber *) [colleague objectForKey: @"Precision"] intValue];
            pointMarker.style = AGSSimpleMarkerSymbolStyleCircle;    
            
            AGSPoint *wgspoint = [AGSPoint pointWithX:lon y:lat spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]];
            AGSGeometry *mapPoint = [_geometryEngine projectGeometry:wgspoint toSpatialReference:self.mapView.spatialReference];
            
//            LocationInfoTemplate * template = [[LocationInfoTemplate alloc] init];
            AGSCalloutTemplate* template = [[AGSCalloutTemplate alloc] init] ;
            template.titleTemplate = @"${Username}"; 
            template.detailTemplate = @"${TimeStamp}"; 
            
            AGSGraphic *location = [[AGSGraphic alloc] initWithGeometry: mapPoint 
                                                                 symbol: pointMarker 
                                                             attributes: [colleague mutableCopy]
                                                   infoTemplateDelegate: template]; //template];

            [_trackLayer addGraphic:location];
            //template = Nil;
        }


I've got the following issue.
When the user taps on the graphic, the callout is supposed to be shown. But the application crashes in some SDK assembly, to be specific:

0x0011bed8  <+0052>  tst.w r0, #255 ; 0xff
in the [AGSMapView setupCalloutUiForGraphic:mapPoint]

I've tried to use my own TemplateClass (LocationInfoTemplate) and the AGSCalloutTemplate class, both had the same result.

To debug this, i've added the following function:

- (BOOL)mapView:(AGSMapView *)mapView shouldShowCalloutForGraphic:(AGSGraphic *)graphic {
    NSLog(@"Click");
    
    return true;
}

Just to see what's in the Graphic object.

And i was surprised:
First run: _infoTemplateDelegate UIImage * 0xde9ad50
Second run: _infoTemplateDelegate __NSCFNumber * 0xde9acd0

I think i can say that the infoTemplate is NOT retained!

What's the problem here?
I'm using the 2.1 SDK, i'm using the latest Xcode (With ARC) and the latest iOS....

--Edit-- Updated tot 2.2.1 SDK, same behavior.
0 Kudos
9 Replies
NimeshJarecha
Esri Regular Contributor
You should create a retain property for  AGSCalloutTemplate *template.

Regards,
Nimesh
0 Kudos
ReneNijkamp
New Contributor
I've added the following to my header file:


    LocationInfoTemplate *_locationInfoTemplate;

@property (nonatomic, retain) LocationInfoTemplate * locationInfoTemplate;


But it still fails.

I miss the old-skool Retain command, but i can't use it when using ARC.. 😞
0 Kudos
NimeshJarecha
Esri Regular Contributor
Did you do following? And it still crashing?
           
self.locationInfoTemplate * template = [[LocationInfoTemplate alloc] init];
//AGSCalloutTemplate* template = [[AGSCalloutTemplate alloc] init] ;
self.template.titleTemplate = @"${Username}"; 
self.template.detailTemplate = @"${TimeStamp}"; 
            
AGSGraphic *location = [[AGSGraphic alloc] initWithGeometry: mapPoint 
                                                                 symbol: pointMarker 
                                                             attributes: [colleague mutableCopy]
                                                   infoTemplateDelegate:self.template]; //template];


Also, you're using geometry engine in following code line. I hope you are initializing it. Like, AGSGeometryEngine *_geometryEngine = [AGSGeometryEngine defaultGeometryEngine];

AGSGeometry *mapPoint = [_geometryEngine projectGeometry:wgspoint toSpatialReference:self.mapView.spatialReference];


If you are doing all above then please attach your sample project so I can have a look at it.

Regards,
Nimesh
0 Kudos
ReneNijkamp
New Contributor
Forgot to include in my comments:

I'm looping through a dictionary while executing the above code.... (I'm adding a couple of graphics to the layer)
0 Kudos
NimeshJarecha
Esri Regular Contributor
My last response helped you any way? If not, attach your sample project.

Regards,
Nimesh
0 Kudos
NoureddineEl-zaatari
New Contributor
My last response helped you any way? If not, attach your sample project.

Regards,
Nimesh


hello,

im facing the same problem after converting the project to ARC, im adding AGSGraphic to the graphics layer in a loop, when i click on the graphics point to show the callout, it gives this error

AGSCalloutTemplate respondsToSelector:]: message sent to deallocated instance 0xfd807a0


thanks for any help
0 Kudos
NimeshJarecha
Esri Regular Contributor
Did you create a strong property for AGSCalloutTemplate?

in .h file
@property (nonatomic, strong) AGSCalloutTemplate *calloutTemplate;

in .m file
@synthesize calloutTemplate;
self.calloutTemplate=[[AGSCalloutTemplate alloc]init];

Regards,
Nimesh
0 Kudos
AaronConnolly
Occasional Contributor
Forgot to include in my comments:

I'm looping through a dictionary while executing the above code.... (I'm adding a couple of graphics to the layer)


If you loop through a dictionary and create multiple AGSInfoTemplate objects, be sure to put them in a retained (strong) NSMutableArray or some other data structure. That should keep them around when the graphic is tapped.
0 Kudos
GaryThorne
New Contributor
can any one help me please... i want to show detailed page when user tabs on accessory button? i do not know how as i am new to iOS .
0 Kudos