2012-07-31 127 views
0

我目前正在使用plist在地图上放置注释,我设法做到这一点,但即时通讯现在有问题试图从地图视图转到详细视图并从plist中携带信息。地图查看详细查看使用列表

我已经设置了plist,因此它在mapview中有标题和副标题,然后我设置了一个孩子,并且这转到了信息即时消息,试图在详细视图中访问。

我已经设法让它进入详细视图,但它没有采取任何信息,因为我无法解决所需的代码。

我希望这一切都有道理,因为我有点困惑自己。感谢您对任何人的帮助,在此,你将是一个生命的救星(在某种程度上)

继承人的代码

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> 

再次感谢你对此的任何帮助,这将是非常有益的。

回答

0

我假设MyAnnotation类包含有关您需要的注释的所有信息。
它来自plist的事实在这一点上是无关紧要的。


首先,在ViewController2,添加属性为注释:

@property (nonatomic, retain) MyAnnotation *annotation; 


接下来,在calloutAccessoryControlTapped委托方法,设置属性:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    NSLog(@"tapped"); 
    ViewController2 *dvController = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]]; 

    dvController.annotation = (MyAnnotation *)view.annotation; 

    [self.navigationController pushViewController:dvController animated:YES]; 
} 

ViewController2,你现在可以使用annotation属性来配置显示。

+0

非常感谢这很棒 – 2012-07-31 21:20:37