Reputation: 4222
I have a map view that instantiates a presentation model for running all it's logic in my application. I have a list component. User selects some data they want to see on the map. This gets sent to my model and once update is called on the view I pass an NSObject over to the Map view and then want to hand off this data to the PM in order to run logic on the view.
Here is my code for Map view. The very last line is where things crash "[pm showMKL:d];" gets called. If I comment out this line things run smooth.
This is an iOS 6 app so ARC is being used. Some searching suggested a memory leak but running the profiler didn't seem to suggest that. Also I was not able to produce the crash if I run the app with profiling on.
#import "MapView.h"
@implementation MapView
-(id)initWithModel:(MainDM*)dm:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
_dm = dm;
[_dm register:self];
pm = [[MapPM alloc] initWithModel:_dm];
CLLocationCoordinate2D coord = {.latitude = 32.61724, .longitude = -106.74128};
MKCoordinateSpan span = {.latitudeDelta = 1, .longitudeDelta = 1};
MKCoordinateRegion region = {coord, span};
[self setRegion:region];
}
return self;
}
-(void)update:(DataObject*)data
{
if([[data getType] isEqualToString:@"CURRENT_KML_CHANGE"])
{
KmlVO *d = (KmlVO*)[data getData];
[pm showMKL:d];
}
}
@end
Here is the .h for MapView
#import <MapKit/MapKit.h>
#import "MainDM.h"
#import "BBView.h"
#import "MapPM.h"
@interface MapView : MKMapView <BBView>
@property(nonatomic,strong)MainDM *dm;
@property(nonatomic,strong)MapPM *pm;
-(void)update:(DataObject*)data;
-(id)initWithModel:(MainDM*)dm:(CGRect)frame;
@end
Here is the MapPM code.
#import "MapPM.h"
@implementation MapPM
-(id)initWithModel:(MainDM *)dm
{
self = [super init];
if(self)
{
_baseMaps = [[NSMutableArray alloc] init];
_dm = dm;
}
}
-(void)showMKL:(KmlVO*)vo
{
if([_baseMaps containsObject:vo])
{
NSLog(@"not added");
}
else
{
NSLog(@"added kml");
[_baseMaps addObject:vo];
}
}
@end
here is the .h for the PM
#import <Foundation/Foundation.h>
#import "MainDM.h"
#import "KmlVO.h"
@interface MapPM : NSObject
@property(nonatomic, retain)NSMutableArray * baseMaps;
@property(nonatomic, retain)MainDM *dm;
-(id)initWithModel:(MainDM *)dm;
-(void)showMKL:(KmlVO*)vo;
@end
Upvotes: 0
Views: 85
Reputation: 19030
I didn't need to see your header files after all.
-(id)initWithModel:(MainDM *)dm
{
self = [super init];
if(self)
{
_baseMaps = [[NSMutableArray alloc] init];
_dm = dm;
}
}
You're not returning self, and as such, you're performing showMKL on an undefined object. Did you check your warnings?
Also, you're using properties (not instance variables within @interface like you led us to believe). As such, [pm showMKL:data]
should really be [self.pm showMKL:data]
.
Upvotes: 1