私は現在、地図上に注釈を配置するために plist を使用しています。これを行うことはできましたが、地図ビューから詳細ビューに移動して plist から情報を取得しようとすると問題が発生します。
マップビューにタイトルとサブタイトルが含まれるように plist を設定しました。次に、子を設定しました。これは、詳細ビューでアクセスしようとしている情報に移動します。
詳細ビューに移動することはできましたが、それを行うために必要なコードを理解できないため、情報を取得しません。
私は少し混乱しているので、これがすべて意味をなすことを願っています。これについて誰か助けてくれてありがとう、あなたは命の恩人になるでしょう(一種の)
コードはこちら
BrewMapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface BrewMapViewController : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *map;
NSInteger CurrentLevel;
NSString *CurrentTitle;
NSArray *breweries;
}
@property (nonatomic, retain) NSArray *breweries;
@property (nonatomic, readwrite) NSInteger CurrentLevel;
@property (nonatomic, retain) NSString *CurrentTitle;
@end
BrewMapViewController.h
#import "BrewMapViewController.h"
#import "BrewMapAppDelegate.h"
#import "MyAnnotation.h"
#import "ViewController2.h"
@implementation BrewMapViewController
@synthesize breweries, CurrentLevel, CurrentTitle;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *tempArray = [[NSArray alloc] init];
self.breweries = tempArray;
BrewMapAppDelegate *AppDelegate = (BrewMapAppDelegate *)[[UIApplication sharedApplication] delegate];
self.breweries = [AppDelegate.data objectForKey:@"Hull"];
//breweries = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
// pathForResource:@"test"
// ofType:@"xml"]];
double minLat = [[breweries valueForKeyPath:@"@min.latitude"] doubleValue];
double maxLat = [[breweries valueForKeyPath:@"@max.latitude"] doubleValue];
double minLon = [[breweries valueForKeyPath:@"@min.longitude"] doubleValue];
double maxLon = [[breweries valueForKeyPath:@"@max.longitude"] doubleValue];
MKCoordinateRegion region;
region.center.latitude = (maxLat + minLat) / 2.0;
region.center.longitude = (maxLon + minLon) / 2.0;
region.span.latitudeDelta = (maxLat - minLat) * 1.05;
region.span.longitudeDelta = (maxLon - minLon) * 1.05;
map.region = region;
for (NSDictionary *breweryDict in breweries){
MyAnnotation *annotation = [[MyAnnotation alloc] initWithDictionary:breweryDict];
[map addAnnotation:annotation];
[annotation release];
}
if(CurrentLevel == 0) {
self.navigationItem.title = @"Map";
}
else {
//self.navigationItem.title = CurrentTitle;
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if (map.userLocation == annotation){
return nil;
}
NSString *identifier = @"MY_IDENTIFIER";
MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil){
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:identifier]
autorelease];
annotationView.image = [UIImage imageNamed:@"beer.png"];
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.leftCalloutAccessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pretzel.png"]] autorelease];
}
return annotationView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"tapped");
ViewController2 *dvController = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)dealloc {
[breweries release];
[map release];
[super dealloc];
}
@end
plist
<plist version="1.0">
<dict>
<key>Hull</key>
<array>
<dict>
<key>name</key>
<string>Wynkoop Brewery</string>
<key>address</key>
<string>1634 18th St., Denver, Co 80902</string>
<key>latitude</key>
<real>39.753259</real>
<key>test</key>
<string>beer.png</string>
<key>longitude</key>
<real>-104.99818</real>
<key>Children</key>
<array>
<dict>
<key>Title</key>
<string>Testing</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>Great Divide Brewing</string>
<key>address</key>
<string>2201 Arapahoe Street, Denver, CO 80205</string>
<key>latitude</key>
<real>39.753486</real>
<key>longitude</key>
<real>-104.988736</real>
<key>Children</key>
<array>
<dict>
<key>Title</key>
<string>Testing2</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>Rock Bottom</string>
<key>address</key>
<string>1001 16th Street Denver, CO 80265</string>
<key>latitude</key>
<real>39.747186</real>
<key>longitude</key>
<real>-104.995037</real>
<key>Children</key>
<array>
<dict>
<key>Title</key>
<string>Testing3</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>Brekenridge Brewery</string>
<key>address</key>
<string>471 Kalamath Street, Denver, Colorado 80204</string>
<key>latitude</key>
<real>39.723629</real>
<key>longitude</key>
<real>-105.000237</real>
<key>Children</key>
<array>
<dict>
<key>Title</key>
<string>Testing4</string>
</dict>
</array>
</dict>
</array>
</dict>
</plist>
これについて何か助けてくれてありがとう、それは非常に役に立ちます。