2013-02-24 66 views
1

我对iOS开发完全陌生,正在为当地河流创建地图应用程序。应用程序的要点是允许用户通过选择不同的点来绘制河流上的路线。我正在使用MapKit来解决这个问题,但遇到了一些问题。我的主要问题是如何将一个按钮添加到注释中,以便一旦点击,一个细节窗口就会打开,用户可以了解更多关于该点的信息并将其添加到旅程中。这是我的代码,任何想法都会有帮助!iOS映射应用程序注释中的新视图

#import "ViewController.h" 
#import "CoreLocation/CLLocation.h" 

@interface ViewController() 

@end 



@implementation ViewController 



- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
self.mapView.delegate = self; 
} 

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

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 
{ 


// Add an annotation 
MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; 


point.coordinate = userLocation.coordinate; 
point.title = @"Where am I?"; 
point.subtitle = @"I'm here!!!"; 

[self.mapView addAnnotation:point]; 


point.coordinate = CLLocationCoordinate2DMake(33.62258872997,-86.599988937378); 
point.title = @"Civitan Park"; 
point.subtitle = @"Trussville, AL"; 
[self.mapView addAnnotation:point]; 




} 



@end 

回答

1

你的地图视图的委托应该实现–mapView:viewForAnnotation:并返回,设置它的附件查看属性的一个注释视图。正常情况下,将rightCalloutAccessoryView属性设置为类型为UIButtonTypeDetailDisclosureUIButton。您的地图代表还应实现-mapView:annotationView:calloutAccessoryControlTapped:,当用户点击附件视图中的按钮时,该地图将被调用。然后,您可以将详细视图控制器推入导航堆栈,或其他任何您喜欢的东西。