App Crashing when setting AGSMapViewLayerDelegate

2818
1
05-20-2012 08:50 PM
JasonFoster
New Contributor
I am probably missing somethings but when I set the AGSMapViewLayerDelegate the app crashes.

Here is my code...


// MapViewController.h
#import <ArcGIS/ArcGIS.h>

@interface MapViewController : UIViewController <AGSMapViewLayerDelegate>
{
    AGSMapView *_mapView;
    
}

@end

// MapViewController.m
- (id)init
{
    self = [super init];
    if (self) {
        _mapView = [[AGSMapView alloc]  initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
        //_mapView.layer.delegate = self;
        NSMutableArray *layers =[[NSMutableArray alloc] init];
        
        
        NSURL *tileUrl = [NSURL URLWithString:@"http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"];
        AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:tileUrl]; 
        UIView<AGSLayerView>* tileLyrView = [_mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
        [layers addObject:tileLyrView];
        
        NSURL* dynamicUrl = [NSURL URLWithString: @"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"];
        AGSDynamicMapServiceLayer* dynamicLayer = [AGSDynamicMapServiceLayer dynamicMapServiceLayerWithURL: dynamicUrl];
        UIView<AGSLayerView>* dynamicLyrView = [_mapView addMapLayer:dynamicLayer withName:@"Dynamic Layer"];
        [layers addObject:dynamicLyrView];
        
        // Not using yet
        AGSGraphicsLayer *graphicsLayer = [AGSGraphicsLayer graphicsLayer];
        UIView<AGSLayerView>* graphicLyrView = [_mapView addMapLayer:graphicsLayer withName:@"Graphics Layer"];
        [graphicLyrView setDrawDuringPanning:YES];
        [layers addObject:graphicLyrView];
   
        [self setView:_mapView];
    }
    
    return self;
}


- (void)mapViewDidLoad:(AGSMapView *)mapView {
    // Never fires or crashes before it fires, not sure which one
    NSLog(@"%@", @"mapViewDidLoad");
}




I don't use XIB's, just personal preference.
0 Kudos
1 Reply
NimeshJarecha
Esri Regular Contributor
Change _mapView.layer.delegate = self; to _mapView.layerDelegate = self; and it should work.

Regards,
Nimesh
0 Kudos