I have a frustrating issue with Map Pin annotations.
If i create a single view application with the following code it works fine. No issues.
I have encountered a problem when i attempt to use it in as a scene in my application.
The basis of the application is adding multiple map annotations from a property list.
I create an NSMutableArray from the property list, these are then added through an NSObject and the map is updated with pins and titles.
The Issue.
The mappins are displayed correctly in their correct positions " If i do not add a title".
When I add the title the app crashes.
The view .h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface Citys : UIViewController
@property (nonatomic,strong) IBOutlet MKMapView *mapview;
@end
The View .m
#import "Citys.h"
#import "MapViewAnnotation.h"
@interface Citys ()
@end
@implementation Citys
@synthesize mapview;
- (NSMutableArray *)createAnnotations
{
NSMutableArray *annotations = [[NSMutableArray alloc] init];
/
NSString *path = [[NSBundle mainBundle] pathForResource:@"Locations" ofType:@"plist"];
NSArray *locations = [NSArray arrayWithContentsOfFile:path];
for (NSDictionary *row in locations) {
NSString *title = [row objectForKey:@"title"];
NSNumber *latitude = [row objectForKey:@"latitude"];
NSNumber *longitude = [row objectForKey:@"longitude"];
/
CLLocationCoordinate2D coord;
coord.latitude = latitude.doubleValue;
coord.longitude = longitude.doubleValue;
MapViewAnnotation *annotation = [[MapViewAnnotation alloc] initWithTitle:title AndCoordinate:coord];
[annotations addObject:annotation];
}
return annotations;
}
- (void)viewDidLoad
{
[super viewDidLoad];
/
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0,0.0},{0.0,0.0} };
region.center.latitude = 32.760645;
region.center.longitude = -86.635437;
region.span.latitudeDelta = 7.0f;
region.span.longitudeDelta = 7.0f;;
[mapview setRegion:region animated:YES];
[self.mapview addAnnotations:[self createAnnotations]];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
/
}
@end
The annotation NSOject .h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MapViewAnnotation : NSObject <MKAnnotation>
@property (nonatomic,copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
-(id) initWithTitle:(NSString *) title AndCoordinate:(CLLocationCoordinate2D)coordinate;
@end
The annotation NSObject .m
#import "MapViewAnnotation.h"
@implementation MapViewAnnotation
@synthesize title = _title;
@synthesize coordinate =_coordinate;
-(id) initWithTitle:(NSString *) title AndCoordinate:(CLLocationCoordinate2D)coordinate;
{
self = [super init];
_title = title;
_coordinate = coordinate;
return self;
}
@end
The Property List Structure
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-/
<plist version="1.0">
<array>
<dict>
<key>title</key>
<string>Auburn</string>
<key>latitude</key>
<real>32.609857</real>
<key>longitude</key>
<real>-85.480782</real>
</dict>
<dict>
<key>title</key>
<string>Birmingham</string>
<key>latitude</key>
<real>33.520661</real>
<key>longitude</key>
<real>-86.80249</real>
</dict>
</array>
</plist>
The Error
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
If i run this code as a single view application, this does not happen.
Please Help?
ossieleigh