0

コールアウトのボタンを別のViewControllerに移動して追加情報を表示してから、マップビューに戻ることができるようにしたいと思います。マップはタブ付きのViewControllerの内部にあります。現時点では、コールアウトのボタンをクリックすると、アプリがクラッシュし、スレッドエラーが発生します。現時点で何をすべきかわからない。

これはヘッダーファイルです:

#import UIKit/UIKit.h>
#import MapKit/MapKit.h>
#define METERS_PER_MILE 1609.344

@interface MSKSecondViewController :UIViewController<MKMapViewDelegate>
{
    IBOutlet MKMapView *stillwellMapView;
}
@property (nonatomic, assign) CLLocationCoordinate2D mainEntranceToStillwellCoordinate;
@end

これは実装ファイルです:

@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];
}

- (void)viewDidUnload
{
    stillwellMapView = nil;
    [super viewDidUnload]; 
    // Release any retained subviews of the main view.
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: 
(id<MKAnnotation>)annotation    
{
    MKPinAnnotationView * annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
    UIButton *entranceButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [entranceButton addTarget:self action:@selector(entranceButtonPressed:) 
forControlEvents:UIControlEventTouchUpInside];
    annView.rightCalloutAccessoryView = entranceButton;
    entranceButton = [UIButton buttonWithType:UIButtonTypeCustom];
    entranceButton.frame = CGRectMake(0, 0, 23, 23);
    entranceButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    entranceButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [UIButton buttonWithType:UIButtonTypeDetailDisclosure];  
    annView.animatesDrop=TRUE;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)viewWillAppear:(BOOL)animated 
{  
    //the coordinates in which the map shows once loaded
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 40.831922;
    zoomLocation.longitude= -73.476353; 
    //the amount of area shown by the map when it loads
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation,  
0.15*METERS_PER_MILE, 0.15*METERS_PER_MILE); 
    MKCoordinateRegion adjustedRegion = [stillwellMapView regionThatFits:viewRegion];                
    [stillwellMapView setRegion:adjustedRegion animated:YES]; 
}
@end
4

2 に答える 2

1

TouchUpInsideに登録したイベントをentorButtonで追加します。

-(void) entranceButtonPressed:(UIButton *)sender
{
//Write the controller push code here
}

また、コードでは、rightCalloutAccessoryViewに割り当てられた後、entronmentButtonを再初期化します。

于 2012-08-07T05:01:51.043 に答える
0

mapView:viewForAnnotation:デリゲートメソッド内

-(MKAnnotationView *)mapView:(MKMapView *)mapView
        viewForAnnotation:(id <MKAnnotation>)annotation 

//次の行を追加します

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;

次に、次のデリゲートメソッドで他のViewControllerに移動するコードを実装します

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

ビューコントローラがナビゲーションコントローラ内に埋め込まれていることを確認してください

于 2014-04-07T11:52:51.430 に答える