按下销钉时显示视图

时间:2014-01-14 12:52:29

标签: objective-c button map annotations mkmapview

我有一个代码在MKMapView上显示一个引脚并有一个按钮,我希望当按下该按钮时,它会切换到另一个视图,就像苹果地图一样。 我在这里阅读了一些教程和答案,但每次按下按钮,应用程序都会崩溃。 崩溃日志是“libc ++ abi.dylib:以NSException类型的未捕获异常终止”。这是我的代码:

ThirdViewController.h(mapviewcontroller):

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <Foundation/Foundation.h>




@interface ThirdViewController : UIViewController <MKMapViewDelegate>

@property (nonatomic, copy) NSString *userLatitude;
@property (nonatomic, copy) NSString *userLongitude;
@property (strong, nonatomic) IBOutlet MKMapView *mapview;



@end

ThirdViewController.m(mapviewcontroller):

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    mapview.delegate = self;
    mapview.showsUserLocation = YES;

     UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer     alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
    [self.mapview addGestureRecognizer:longPressGesture];
    [longPressGesture release];

    //Span
    MKCoordinateSpan span;
    span.latitudeDelta = THE_SPAN;
    span.longitudeDelta = THE_SPAN;


    //Annotation
    NSMutableArray * locations = [[NSMutableArray alloc]init];
    CLLocationCoordinate2D location;
    AdressAnnotation *myann;



    //Annotation
    myann = [[AdressAnnotation alloc]init];
    location.latitude = LOCATION_LATITUDE;
    location.longitude = LOCATION_LONGITUDE;
    myann.coordinate = location;
    myann.title = @"Text";
    myann.subtitle = @"Text";
    [locations addObject:myann];



    [self.mapview addAnnotations:locations];



}



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

    if ([(UIButton*)control buttonType] == UIButtonTypeDetailDisclosure){
        PlaceViewController *detailView=[[PlaceViewController alloc]     initWithNibName:@"detailView" bundle:nil];
        [[self navigationController] pushViewController:detailView animated:YES];
        [detailView release];


    }

}

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


    MKPinAnnotationView *pinView = nil;
    if(annotation!= mapview.userLocation)
    {
        static NSString *defaultPin = @"pinIdentifier";
        pinView = (MKPinAnnotationView*)[mapview     dequeueReusableAnnotationViewWithIdentifier:defaultPin];
        if(pinView == nil)
            pinView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation     reuseIdentifier:defaultPin]autorelease];
        pinView.pinColor = MKPinAnnotationColorRed; //Optional
        pinView.canShowCallout = YES; // Optional
        pinView.animatesDrop = YES;
        pinView.draggable = YES;

        pinView.canShowCallout = YES;

        // Add a detail disclosure button to the callout.
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView = rightButton;
    }
    else
    {
        [mapview.userLocation setTitle:@"You are Here!"];
    }
    return pinView;
}

- (void)dealloc {
    [mapview release];
    [super dealloc];
}

@end

0 个答案:

没有答案