2012-08-08 54 views
0

我正在製作一個將使用MKMapKit作爲引腳和註釋的應用程序。除了一些文本之外,我想顯示更多的信息,所以我在標註中創建了一個按鈕,以便我可以將其轉到另一個視圖控制器。目前,標註中的按鈕不起任何作用,因爲沒有代碼可以使其工作。如果有人能夠讓按鈕的代碼轉到不同的視圖控制器,那將會很棒!從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 
{ 

} 

回答

1

請在下方填寫代碼:

-(void) moreInformationButtonPressed:(UIButton *)sender 
{ 
    OtherViewController *controller = [[OtherViewController alloc]initWithNibName:@"OtherViewController" bundle:nil]; 
    [self.navigationController pushViewController:controller animated:YES]; 
    [controller release];  
} 
+0

這會走在其他視圖控制器的自定義類的代碼?或在地圖視圖視圖控制器代碼?現在它在地圖視圖控制器的代碼中,並且有一個錯誤,說我需要聲明控制器和入口視圖控制器? – Klipper 2012-08-08 20:53:45

0

你首先應該做一個標記,你可以知道哪些註釋點擊

moreInformationButton.tag = someIndex; 

然後做動作你要

-(void) moreInformationButtonPressed:(UIButton *)sender 
{ 
    int index = sender.tag; 

    YourController *yc =[[[YourController alloc] initWithIndex:index] autorelease]; 
    [self.navigationController pushViewController:scanView animated:YES]; 
} 
相關問題