Select to view content in your preferred language

AGSLayerDelegate is not being called

837
1
Jump to solution
03-11-2013 04:58 PM
KyunamKim
Esri Contributor
Let's say I have my own delegate class

@interface MyLayerDelegate : NSObject <AGSLayerDelegate>
@end
along with its implementation file.

In my ViewController, I set a delegate like this.

AGSDynamicMapServiceLayer *aLayer = ...;
aLayer.delegate = [[MyLayerDelegate alloc] init];

Why isn't this delegate instance not being called?

When I make ViewController to adopt AGSLayerDelegate and do
aLayer.delegate = self;
Then, this works.

Yes, I'm new to Objective-C, iOS land.

Thanks,
Kyunam
0 Kudos
1 Solution

Accepted Solutions
FrankXia
Esri Contributor
You need to hold the reference to your MyLayerDelegate variable so it wouldn't be released by the system. In your controller class's .h file, add the following line,

@property (nonatomic, strong) MyLayerDelegate *myLayerDelegate;

And then create an object for this class in your controller's .m file, and assign to the variable you declared in the .h file such as

    myLayerDelegate = [[MyLayerDelegate alloc] init];
    yourDynamicLayer.delegate = myLayerDelegate;

That's all.

Frank

View solution in original post

0 Kudos
1 Reply
FrankXia
Esri Contributor
You need to hold the reference to your MyLayerDelegate variable so it wouldn't be released by the system. In your controller class's .h file, add the following line,

@property (nonatomic, strong) MyLayerDelegate *myLayerDelegate;

And then create an object for this class in your controller's .m file, and assign to the variable you declared in the .h file such as

    myLayerDelegate = [[MyLayerDelegate alloc] init];
    yourDynamicLayer.delegate = myLayerDelegate;

That's all.

Frank
0 Kudos