不显示Mapkit Annotation详细信息披露

时间:2014-09-15 08:31:24

标签: ios annotations mapkit detail disclosure

我试图填写详细信息,但它不会产生。编译和构建应用程序时,我没有任何错误或警告,除了这里的一个:" mapView的本地声明隐藏了实例变量。我知道这意味着什么,这意味着它已经在其他地方使用过。当我输入self.webView时,错误消失了,但细节披露仍然没有填充。让我知道我做错了什么:

注释:

MapViewAnnotion.h

#import 
Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapViewAnnotation : NSObject <MKAnnotation> {

NSString *title;
NSString *subtitle;
CLLocationCoordinate2D coordinate;

}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d andSubtitle:(NSString *)sub;

@end

MapViewAnnotation.m

#import "MapViewAnnotation.h"

@implementation MapViewAnnotation

@synthesize title, coordinate,subtitle;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d andSubtitle:(NSString *)sub{
//[super init];
title = ttl;
coordinate = c2d;
subtitle = sub;
return self;
}

- (void)dealloc {
//  [title release];
//  [super dealloc];
}



@end

然后......

MapViewController.h

#import <UIKit/UIKit.h>
#import "RESideMenu.h"
#import <MapKit/MapKit.h>

@interface MapViewController : UIViewController
{
IBOutlet MKMapView *mapView;
IBOutlet UISegmentedControl *segmentedControl;

}


@property (nonatomic, retain) MKMapView *mapView;
@property (nonatomic, retain) UISegmentedControl *segmentedControl;

- (IBAction)segmentedControllChanged:(id)sender;

@end

MapViewController.m

#import "MapViewController.h"
#import "MapViewAnnotation.h"
#import "config.h"

@interface MapViewController ()

@end

@implementation MapViewController
@synthesize mapView, segmentedControl;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];


// Do any additional setup after loading the view from its nib.

self.title = [NSString stringWithFormat:@"\tCurrently In : %@",[config getSubTitle]];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)];
[self.navigationItem.leftBarButtonItem setTintColor:[UIColor colorWithRed:(93/255.0) green:(149/255.0) blue:(197/255.0) alpha:1]];

// All map stuff

mapView.showsUserLocation = YES;

double cost2 = [config getLatitude];
double cost = [config getLongitude];
CLLocationCoordinate2D location;
location.latitude =  cost2;
location.longitude = cost;

// Add the annotation to our map view

MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:[config getTitle] andCoordinate:location andSubtitle:[config getSubTitle]];

[self.mapView addAnnotation:newAnnotation];


// Do any additional setup after loading the view from its nib.

MKCoordinateRegion region;
region.center.latitude = (double)  cost2;
region.center.longitude = (double) cost;
region.span = MKCoordinateSpanMake(.99, .99);
region = [self.mapView regionThatFits:region];
[self.mapView setRegion:region animated:YES];

//!!! Map Points

// UNITED STATES

    // Alaska

MKPointAnnotation *anchorage = [[MKPointAnnotation alloc] init];
anchorage.coordinate = CLLocationCoordinate2DMake(61.218056, -149.900278);
anchorage.title = @"Anchorage";
anchorage.subtitle = @"Alaska";
[mapView addAnnotation:anchorage];

MKPointAnnotation *chena = [[MKPointAnnotation alloc] init];
chena.coordinate = CLLocationCoordinate2DMake(64.88349, -146.855596);
chena.title = @"Chena Hot Springs";
chena.subtitle = @"Alaska";
[mapView addAnnotation:chena];

MKPointAnnotation *healy = [[MKPointAnnotation alloc] init];
healy.coordinate = CLLocationCoordinate2DMake(63.869738, -149.021511);
healy.title = @"Healy";
healy.subtitle = @"Alaska";
[mapView addAnnotation:healy];

MKPointAnnotation *palmer = [[MKPointAnnotation alloc] init];
palmer.coordinate = CLLocationCoordinate2DMake(61.599722, -149.112778);
palmer.title = @"Palmer";
palmer.subtitle = @"Alaska";
[mapView addAnnotation:palmer];

MKPointAnnotation *seward = [[MKPointAnnotation alloc] init];
seward.coordinate = CLLocationCoordinate2DMake(60.104167, -149.442222);
seward.title = @"Seward";
seward.subtitle = @"Alaska";
[mapView addAnnotation:seward];

MKPointAnnotation *wasilla = [[MKPointAnnotation alloc] init];
wasilla.coordinate = CLLocationCoordinate2DMake(61.581389, -149.439444);
wasilla.title = @"Wasilla";
wasilla.subtitle = @"Alaska";
[mapView addAnnotation:wasilla];

    // Arizona

MKPointAnnotation *tucson = [[MKPointAnnotation alloc] init];
tucson.coordinate = CLLocationCoordinate2DMake(32.221743, -110.926479);
tucson.title = @"Tuscon";
tucson.subtitle = @"Arizona";
[mapView addAnnotation:tucson];

MKPointAnnotation *phoenix = [[MKPointAnnotation alloc] init];
phoenix.coordinate = CLLocationCoordinate2DMake(33.448377, -112.074037);
phoenix.title = @"Phoenix";
phoenix.subtitle = @"Arizona";
[mapView addAnnotation:phoenix];

    // California

MKPointAnnotation *anaheim = [[MKPointAnnotation alloc] init];
anaheim.coordinate = CLLocationCoordinate2DMake(33.835293, -117.914504);
anaheim.title = @"Anaheim";
anaheim.subtitle = @"California";
[mapView addAnnotation:anaheim];

    // Colorado

MKPointAnnotation *denver = [[MKPointAnnotation alloc] init];
denver.coordinate = CLLocationCoordinate2DMake(39.737567, -104.984718);
denver.title = @"Denver";
denver.subtitle = @"Colorado";
[mapView addAnnotation:denver];

    // Georgia

MKPointAnnotation *augusta = [[MKPointAnnotation alloc] init];
augusta.coordinate = CLLocationCoordinate2DMake(33.473498, -82.010515);
augusta.title = @"Augusta";
augusta.subtitle = @"Georgia";
[mapView addAnnotation:augusta];

    // Hawaii

MKPointAnnotation *honolulu = [[MKPointAnnotation alloc] init];
honolulu.coordinate = CLLocationCoordinate2DMake(21.306944, -157.858333);
honolulu.title = @"Honolulu";
honolulu.subtitle = @"Hawaii";
[mapView addAnnotation:honolulu];

    // Indiana

MKPointAnnotation *terrehaute = [[MKPointAnnotation alloc] init];
terrehaute.coordinate = CLLocationCoordinate2DMake(39.466703, -87.413909);
terrehaute.title = @"Terre Haute";
terrehaute.subtitle = @"Indiana";
[mapView addAnnotation:terrehaute];

MKPointAnnotation *indianapolis = [[MKPointAnnotation alloc] init];
indianapolis.coordinate = CLLocationCoordinate2DMake(39.768403, -86.158068);
indianapolis.title = @"Indianapolis";
indianapolis.subtitle = @"Indiana";
[mapView addAnnotation:indianapolis];

    // Michigan

MKPointAnnotation *westland = [[MKPointAnnotation alloc] init];
westland.coordinate = CLLocationCoordinate2DMake(42.324204, -83.400211);
westland.title = @"Westland";
westland.subtitle = @"Michigan";
[mapView addAnnotation:westland];

MKPointAnnotation *detroit = [[MKPointAnnotation alloc] init];
detroit.coordinate = CLLocationCoordinate2DMake(42.331427, -83.045754);
detroit.title = @"Detroit";
detroit.subtitle = @"Michigan";
[mapView addAnnotation:detroit];

    // Missouri

MKPointAnnotation *stlouis = [[MKPointAnnotation alloc] init];
stlouis.coordinate = CLLocationCoordinate2DMake(38.627003, -90.199404);
stlouis.title = @"St Louis";
stlouis.subtitle = @"Missouri";
[mapView addAnnotation:stlouis];

    // New York

MKPointAnnotation *newyork = [[MKPointAnnotation alloc] init];
newyork.coordinate = CLLocationCoordinate2DMake(40.712784, -74.005941 );
newyork.title = @"New York";
newyork.subtitle = @"New York";
[mapView addAnnotation:newyork];

MKPointAnnotation *manhattan = [[MKPointAnnotation alloc] init];
manhattan.coordinate = CLLocationCoordinate2DMake(40.790278, -73.959722);
manhattan.title = @"Manhattan";
manhattan.subtitle = @"New York";
[mapView addAnnotation:manhattan];

MKPointAnnotation *queens = [[MKPointAnnotation alloc] init];
queens.coordinate = CLLocationCoordinate2DMake(40.75, -73.866667);
queens.title = @"Queens";
queens.subtitle = @"New York";
[mapView addAnnotation:queens];

    // North Carolina

MKPointAnnotation *asheville = [[MKPointAnnotation alloc] init];
asheville.coordinate = CLLocationCoordinate2DMake(35.595058, -82.551487);
asheville.title = @"Asheville";
asheville.subtitle = @"North Carolina";
[mapView addAnnotation:asheville];

MKPointAnnotation *butner = [[MKPointAnnotation alloc] init];
butner.coordinate = CLLocationCoordinate2DMake(36.132089, -78.756671);
butner.title = @"Butner";
butner.subtitle = @"North Carolina";
[mapView addAnnotation:butner];

MKPointAnnotation *creedmoor = [[MKPointAnnotation alloc] init];
creedmoor.coordinate = CLLocationCoordinate2DMake(36.122368, -78.686115);
creedmoor.title = @"Creedmoor";
creedmoor.subtitle = @"North Carolina";
[mapView addAnnotation:creedmoor];

MKPointAnnotation *charlotte = [[MKPointAnnotation alloc] init];
charlotte.coordinate = CLLocationCoordinate2DMake(35.227087, -80.843127);
charlotte.title = @"Charolette";
charlotte.subtitle = @"North Carolina";
[mapView addAnnotation:charlotte];

MKPointAnnotation *fayetteville = [[MKPointAnnotation alloc] init];
fayetteville.coordinate = CLLocationCoordinate2DMake(35.052664, -78.878358);
fayetteville.title = @"Fayetteville";
fayetteville.subtitle = @"North Carolina";
[mapView addAnnotation:fayetteville];

MKPointAnnotation *jacksonville = [[MKPointAnnotation alloc] init];
jacksonville.coordinate = CLLocationCoordinate2DMake(34.754052, -77.430241);
jacksonville.title = @"Jacksonville";
jacksonville.subtitle = @"North Carolina";
[mapView addAnnotation:jacksonville];

MKPointAnnotation *greenville = [[MKPointAnnotation alloc] init];
greenville.coordinate = CLLocationCoordinate2DMake(35.612661, -77.366354);
greenville.title = @"Greenville";
greenville.subtitle = @"North Carolina";
[mapView addAnnotation:greenville];

MKPointAnnotation *greensboro = [[MKPointAnnotation alloc] init];
greensboro.coordinate = CLLocationCoordinate2DMake(36.072635, -79.791975);
greensboro.title = @"Greensboro";
greensboro.subtitle = @"North Carolina";
[mapView addAnnotation:greensboro];

MKPointAnnotation *winston = [[MKPointAnnotation alloc] init];
winston.coordinate = CLLocationCoordinate2DMake(36.09986, -80.244216);
winston.title = @"Winston";
winston.subtitle = @"North Carolina";
[mapView addAnnotation:winston];

MKPointAnnotation *boone = [[MKPointAnnotation alloc] init];
boone.coordinate = CLLocationCoordinate2DMake(36.216795, -81.674552);
boone.title = @"Boone";
boone.subtitle = @"North Carolina";
[mapView addAnnotation:boone];

MKPointAnnotation *raleigh = [[MKPointAnnotation alloc] init];
raleigh.coordinate = CLLocationCoordinate2DMake(35.77959, -78.638179);
raleigh.title = @"Raleigh";
raleigh.subtitle = @"North Carolina";
[mapView addAnnotation:raleigh];

MKPointAnnotation *durham = [[MKPointAnnotation alloc] init];
durham.coordinate = CLLocationCoordinate2DMake(35.994033, -78.898619);
durham.title = @"Durham";
durham.subtitle = @"North Carolina";
[mapView addAnnotation:durham];

MKPointAnnotation *goldsboro = [[MKPointAnnotation alloc] init];
goldsboro.coordinate = CLLocationCoordinate2DMake(35.384884, -77.992765);
goldsboro.title = @"Goldsboro";
goldsboro.subtitle = @"North Carolina";
[mapView addAnnotation:goldsboro];

MKPointAnnotation *kinston = [[MKPointAnnotation alloc] init];
kinston.coordinate = CLLocationCoordinate2DMake(35.262664, -77.581635);
kinston.title = @"Kinston";
kinston.subtitle = @"North Carolina";
[mapView addAnnotation:kinston];

MKPointAnnotation *lagrange = [[MKPointAnnotation alloc] init];
lagrange.coordinate = CLLocationCoordinate2DMake(35.306829, -77.788034);
lagrange.title = @"La Grange";
lagrange.subtitle = @"North Carolina";
[mapView addAnnotation:lagrange];

MKPointAnnotation *oxford = [[MKPointAnnotation alloc] init];
oxford.coordinate = CLLocationCoordinate2DMake(36.3107, -78.590835);
oxford.title = @"Oxford";
oxford.subtitle = @"North Carolina";
[mapView addAnnotation:oxford];

MKPointAnnotation *morrisville = [[MKPointAnnotation alloc] init];
morrisville.coordinate = CLLocationCoordinate2DMake(35.823483, -78.825562);
morrisville.title = @"Morrisville";
morrisville.subtitle = @"North Carolina";
[mapView addAnnotation:morrisville];

MKPointAnnotation *roxboro = [[MKPointAnnotation alloc] init];
roxboro.coordinate = CLLocationCoordinate2DMake(36.393752, -78.982788);
roxboro.title = @"Roxboro";
roxboro.subtitle = @"North Carolina";
[mapView addAnnotation:roxboro];

MKPointAnnotation *henderson = [[MKPointAnnotation alloc] init];
henderson.coordinate = CLLocationCoordinate2DMake(36.329591, -78.399164);
henderson.title = @"Henderson";
henderson.subtitle = @"North Carolina";
[mapView addAnnotation:henderson];

MKPointAnnotation *chapelhill = [[MKPointAnnotation alloc] init];
chapelhill.coordinate = CLLocationCoordinate2DMake(35.9132, -79.055845);
chapelhill.title = @"Chapel Hill";
chapelhill.subtitle = @"North Carolina";
[mapView addAnnotation:chapelhill];

MKPointAnnotation *apex = [[MKPointAnnotation alloc] init];
apex.coordinate = CLLocationCoordinate2DMake(35.732652, -78.850286);
apex.title = @"Apez";
apex.subtitle = @"North Carolina";
[mapView addAnnotation:apex];

    // Oklahoma

MKPointAnnotation *lawton = [[MKPointAnnotation alloc] init];
lawton.coordinate = CLLocationCoordinate2DMake(34.603567, -98.395929);
lawton.title = @"Lawton";
lawton.subtitle = @"Oklahoma";
[mapView addAnnotation:lawton];

    // Pennsylvania

MKPointAnnotation *mercersburg = [[MKPointAnnotation alloc] init];
mercersburg.coordinate = CLLocationCoordinate2DMake(39.82787, -77.903331);
mercersburg.title = @"Mercersburg";
mercersburg.subtitle = @"Pennsylvania";
[mapView addAnnotation:mercersburg];

    // South Carolina

MKPointAnnotation *columbia = [[MKPointAnnotation alloc] init];
columbia.coordinate = CLLocationCoordinate2DMake(34.00071, -81.034814);
columbia.title = @"Columbia";
columbia.subtitle = @"South Carolina";
[mapView addAnnotation:columbia];

MKPointAnnotation *greenville2 = [[MKPointAnnotation alloc] init];
greenville2.coordinate = CLLocationCoordinate2DMake(34.852618, -82.39401);
greenville2.title = @"Greenville";
greenville2.subtitle = @"South Carolina";
[mapView addAnnotation:greenville2];

MKPointAnnotation *mbeach = [[MKPointAnnotation alloc] init];
mbeach.coordinate = CLLocationCoordinate2DMake(33.68906, -78.886694);
mbeach.title = @"Mrytle Beach";
mbeach.subtitle = @"South Carolina";
[mapView addAnnotation:mbeach];

    // Tennessee

MKPointAnnotation *chattanooga = [[MKPointAnnotation alloc] init];
chattanooga.coordinate = CLLocationCoordinate2DMake(35.04563, -85.30968);
chattanooga.title = @"Chattanooga";
chattanooga.subtitle = @"Tennessee";
[mapView addAnnotation:chattanooga];

MKPointAnnotation *manchester = [[MKPointAnnotation alloc] init];
manchester.coordinate = CLLocationCoordinate2DMake(35.481743, -86.088599);
manchester.title = @"Manchester";
manchester.subtitle = @"Tennessee";
[mapView addAnnotation:manchester];

MKPointAnnotation *nashville = [[MKPointAnnotation alloc] init];
nashville.coordinate = CLLocationCoordinate2DMake(36.166667, -86.783333);
nashville.title = @"Nashville";
nashville.subtitle = @"Tennessee";
[mapView addAnnotation:nashville];

MKPointAnnotation *knoxville = [[MKPointAnnotation alloc] init];
knoxville.coordinate = CLLocationCoordinate2DMake(35.960638, -83.920739);
knoxville.title = @"Knoxville";
knoxville.subtitle = @"Tennessee";
[mapView addAnnotation:knoxville];

   // Washington D.C.

MKPointAnnotation *wdc = [[MKPointAnnotation alloc] init];
wdc.coordinate = CLLocationCoordinate2DMake(38.907192, -77.036871);
wdc.title = @"Washington D.C.";
[mapView addAnnotation:wdc];

    // Virgina

MKPointAnnotation *alexandria = [[MKPointAnnotation alloc] init];
alexandria.coordinate = CLLocationCoordinate2DMake(38.804836, -77.046921);
alexandria.title = @"Alexandria";
alexandria.subtitle = @"Virgina";
[mapView addAnnotation:alexandria];

MKPointAnnotation *arlington = [[MKPointAnnotation alloc] init];
arlington.coordinate = CLLocationCoordinate2DMake(38.87997, -77.10677);
arlington.title = @"Arlington";
arlington.subtitle = @"Virgina";
[mapView addAnnotation:arlington];

MKPointAnnotation *fairfax = [[MKPointAnnotation alloc] init];
fairfax.coordinate = CLLocationCoordinate2DMake(38.846224, -77.306373);
fairfax.title = @"Fairfax";
fairfax.subtitle = @"Virgina";
[mapView addAnnotation:fairfax];

MKPointAnnotation *williamsburg = [[MKPointAnnotation alloc] init];
williamsburg.coordinate = CLLocationCoordinate2DMake(37.270702, -76.707457);
williamsburg.title = @"Williamsburg";
williamsburg.subtitle = @"Virgina";
[mapView addAnnotation:williamsburg];


// OCONUS

    // ASIA

        // SOUTH KOREA

MKPointAnnotation *seoul = [[MKPointAnnotation alloc] init];
seoul.coordinate = CLLocationCoordinate2DMake(37.566535, 126.977969);
seoul.title = @"Seoul";
seoul.subtitle = @"South Korea";
[mapView addAnnotation:seoul];

MKPointAnnotation *suwon = [[MKPointAnnotation alloc] init];
suwon.coordinate = CLLocationCoordinate2DMake(37.263573, 127.028601);
suwon.title = @"Suwon";
suwon.subtitle = @"South Korea";
[mapView addAnnotation:suwon];

MKPointAnnotation *incheon = [[MKPointAnnotation alloc] init];
incheon.coordinate = CLLocationCoordinate2DMake(37.456256, 126.705206);
incheon.title = @"Incheon";
incheon.subtitle = @"South Korea";
[mapView addAnnotation:incheon];

MKPointAnnotation *sokcho = [[MKPointAnnotation alloc] init];
sokcho.coordinate = CLLocationCoordinate2DMake(38.207015, 128.591849);
sokcho.title = @"Sokcho-si";
sokcho.subtitle = @"South Korea";
[mapView addAnnotation:sokcho];

MKPointAnnotation *osan = [[MKPointAnnotation alloc] init];
osan.coordinate = CLLocationCoordinate2DMake(37.14981, 127.077221);
osan.title = @"Osan";
osan.subtitle = @"South Korea";
[mapView addAnnotation:osan];

MKPointAnnotation *pyeongtaek = [[MKPointAnnotation alloc] init];
pyeongtaek.coordinate = CLLocationCoordinate2DMake(36.992108, 127.112945);
pyeongtaek.title = @"Pyeongtaek-si";
pyeongtaek.subtitle = @"South Korea";
[mapView addAnnotation:pyeongtaek];

        // THAILAND

        MKPointAnnotation *bangkok = [[MKPointAnnotation alloc] init];
        bangkok.coordinate = CLLocationCoordinate2DMake(13.727896, 100.524123);
        bangkok.title = @"Bangkok";
        bangkok.subtitle = @"Thailand";
        [mapView addAnnotation:bangkok];

}


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
if (!pinView) {
    pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
    pinView.pinColor = MKPinAnnotationColorRed;
    pinView.animatesDrop = YES;
    pinView.canShowCallout = YES;

    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.rightCalloutAccessoryView = rightButton;
} else {
    pinView.annotation = annotation;
}
return pinView;
}

- (void)showMenu
{
[self.sideMenuViewController presentMenuViewController];
}

- (IBAction)segmentedControllChanged:(id)sender {

if (segmentedControl.selectedSegmentIndex == 0) {
    mapView.mapType = MKMapTypeStandard;
}else if (segmentedControl.selectedSegmentIndex == 1) {
    mapView.mapType = MKMapTypeHybrid;
    double cost2 = [config getLatitude];
    double cost = [config getLongitude];
    CLLocationCoordinate2D location;
    location.latitude =  cost2;
    location.longitude = cost;
    MKCoordinateRegion region;
    region.center.latitude = (double)  cost2;
    region.center.longitude = (double) cost;
    region.span = MKCoordinateSpanMake(.199, .199);
    region = [self.mapView regionThatFits:region];
    [self.mapView setRegion:region animated:YES];
} else if (segmentedControl.selectedSegmentIndex == 2) {
    mapView.mapType = MKMapTypeSatellite;
    double cost2 = [config getLatitude];
    double cost = [config getLongitude];
    CLLocationCoordinate2D location;
    location.latitude =  cost2;
    location.longitude = cost;
    MKCoordinateRegion region;
    region.center.latitude = (double)  cost2;
    region.center.longitude = (double) cost;
    region.span = MKCoordinateSpanMake(.299, .299);
    region = [self.mapView regionThatFits:region];
    [self.mapView setRegion:region animated:YES];
}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


@end

欢迎任何帮助:)谢谢

0 个答案:

没有答案