2013-02-24 34 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:,當用戶點擊附件視圖中的按鈕時,該地圖將被調用。然後,您可以將詳細視圖控制器推入導航堆棧,或其他任何您喜歡的東西。