我正在制作一个将 MKMapKit 用于引脚和注释的应用程序。除了一些文本之外,我还想显示更多信息,所以我在标注中创建了一个按钮,以便将其转到另一个视图控制器。目前,标注中的按钮没有做任何事情,因为没有代码可以让它工作。如果有人可以为按钮编写代码以转到不同的视图控制器,那就太好了!
头文件
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#define METERS_PER_MILE 1609.344
@interface MSKSecondViewController :UIViewController<MKMapViewDelegate>
{
IBOutlet MKMapView *stillwellMapView;
int difficultyOfTrailOverlay;
}
@property (nonatomic, assign) CLLocationCoordinate2D mainEntranceToStillwellCoordinate;
@end
这是实现文件
#import "MSKSecondViewController.h"
@interface MSKSecondViewController ()
@end
@implementation MSKSecondViewController
@synthesize mainEntranceToStillwellCoordinate;
- (void)viewDidLoad
{
[super viewDidLoad];
stillwellMapView.delegate=self;
// Do any additional setup after loading the view, typically from a nib.
[self mainEntrancetoStillwellCoordinate];
[self bambooForestCoordinate];
}
- (void)mainEntrancetoStillwellCoordinate
{
MKPointAnnotation * main = [[MKPointAnnotation alloc]init];
CLLocationCoordinate2D mainLocation;
mainLocation.latitude = 40.831685;
mainLocation.longitude = -73.477453;
[main setCoordinate:mainLocation];
[main setTitle:@"Entrance"];
[main setSubtitle:@"Main"];
[stillwellMapView addAnnotation:main];
}
- (void)bambooForestCoordinate
{
MKPointAnnotation * bambooForest = [[MKPointAnnotation alloc]init];
CLLocationCoordinate2D bambooForestLocation;
bambooForestLocation.latitude = 40.829118;
bambooForestLocation.longitude = -73.466443;
[bambooForest setCoordinate:bambooForestLocation];
[bambooForest setTitle:@"Bamboo Forest"];
[bambooForest setSubtitle:@"Exit to Woodbury"];
[stillwellMapView addAnnotation:bambooForest];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation
(id<MKAnnotation>)annotation
{
MKPinAnnotationView * annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:nil];
UIButton *moreInformationButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[moreInformationButton addTarget:self action:@selector(moreInformationButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = moreInformationButton;
moreInformationButton.frame = CGRectMake(0, 0, 23, 23);
moreInformationButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
moreInformationButton.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentCenter;
annView.pinColor =MKPinAnnotationColorGreen;
annView.animatesDrop = true;
annView.canShowCallout = TRUE;
return annView;
}
我不确定这是否是我需要添加的,以及这里需要进入的内容
-(void) moreInformationButtonPressed:(UIButton *)sender
{
}