I am working in MapKit and trying to build out detail views of annotations through the "calloutAccessoryControlTapped" control. I want to pull a local HTML file detailing the points on the map into an existing UIWebView that I use in another portion of the app from the plist that stores all of the annotation data.
I am able to create the annotations, add unique icons for the annotations and push a the UIWebView, but I cannot for the life of me figure out how to load these local detail webpages into the view.
Has anyone faced this and come up with a viable solution?
plist item (truncated for this post - but they repeat for all points on the map)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd>">
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>Title</string>
<key>address</key>
<string>Subtitle</string>
<key>latitude</key>
<real>28.538335</real>
<key>longitude</key>
<real>-81.379236</real>
<key>imageName</key>
<string>pin_001.png</string>
<key>bulletName</key>
<string>pin_001a.png</string>
<key>detailURL</key>
<string>test.html</string>
</dict>
</array>
</plist>
MyAnnotation.h
Code:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyAnnotation : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *imageName;
NSString *bulletName;
NSString *detailURL;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, retain) NSString *imageName;
@property (nonatomic, retain) NSString *bulletName;
@property (nonatomic, retain) NSString *detailURL;
@end
MyAnnotation.m
Code:
#import "MyAnnotation.h"
@implementation MyAnnotation
@synthesize coordinate, title, subtitle, imageName, bulletName, detailURL;
- (id) initWithDictionary:(NSDictionary *) dict
{
self = [super init];
if (self != nil) {
coordinate.latitude = [[dict objectForKey:@"latitude"] doubleValue];
coordinate.longitude = [[dict objectForKey:@"longitude"] doubleValue];
self.title = [dict objectForKey:@"name"];
self.subtitle = [dict objectForKey:@"address"];
self.imageName = [dict objectForKey:@"imageName"];
self.bulletName = [dict objectForKey:@"bulletName"];
self.detailURL = [dict objectForKey:@"detailURL"];
}
return self;
}
@end
calloutAccessoryControlTapped
Code:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
//this determines what kind of item was selected
if ([control isKindOfClass:[UIButton class]]) {
//pushes the blank WebVC controller for all annotations
WebVC *webVC = [[WebVC alloc] initWithNibName:@"WebVC" bundle:nil];
[self.navigationController pushViewController:webVC animated:YES];
//titles the new view
webVC.title = @"Detail View";
//releases the view
[webVC release];
}
}
The above works as you load a map, select an annotation and click:
Code:
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
The "Detail View" pushes in and loads a blank UIWebView. It is loading those unique local HTML files to showcase detailed descriptions I cannot figure out.
I would be grateful if anyone could help with some direction for solving this conundrum, or if you have worked through this how you successfully managed this process. TIA