2017-07-12 2 views
0

J'ai écrit une application mapView simple. Elle montre deux types de problèmes.Application MapView

1- L'exécution s'arrête sur le fil 1: signal d'erreur SIGABRT.

2- Cette fonction affiche une erreur de compilation.

- (IBAction)findMe:(id)sender { 

    If([[toggleButton titleForState:UIControlStateNormal] isEqualToString:@"Find Me"]) 
    { 
    [toggleButton setTitle:@"Hide Me" forState:UIControlStateNormal]; 
    mapView.showsUserLocation=YES; 
    } 
    else 
    { 
    [toggleButton setTitle:@"Find Me" forState:UIControlStateNormal]; 
    mapView.showsUserLocation=NO; 
    } 

} 

Comment faire pour supprimer ces erreur?

Je veux mettre les coordonnées de plus d'un emplacement dans mon code Je veux montrer l'icône loc.png sur la carte correspondant à ces coordonnées comment je peux accomplir cette tâche?

Vous pouvez voir l'exemple de projet de ce lien: https://drive.google.com/open?id=0B5pNDpbvZ8SnRmNFS0pjVnJFWHc

+0

Vous utilisez un I majuscule dans "Si". Cela devrait être "si", cela pourrait être la cause de l'erreur de compilation. – LoganHenderson

+0

Les erreurs de temps de compilation sont supprimées. Thread 1: signal L'erreur SIGABRT persiste à l'exécution. –

+0

@ user2557829 cette question est répondue dans https://stackoverflow.com/questions/45067276/thread-1-signal-sigabrt-error/45069255#45069255 –

Répondre

0

Vous obtenez erreur de compilation de temps pour 3 raisons:

1) Le « Si » vous utilisez si-else condition doit être " si "c'est-à-dire en minuscules.

2). Vous avez un bouton IBOutlet connect to findMe dans le storyboard qui n'existe pas dans votre contrôleur de vue. Donc, soit l'enlever ou l'ajouter.

3) Vous utilisez MKMapView mais vous n'avez pas ajouté MapKit Framework dans l'option "Link Binaries" dans les phases de construction de votre projet.

Veuillez effectuer toutes ces étapes pour que votre code compilé & soit exécuté sans erreur.

+0

Les erreurs de temps de compilation sont supprimées. L'exécution du programme s'arrête toujours à l'exécution sur Thread 1: erreur de signal SIGABRT. –

+0

Je veux mettre les coordonnées de plus d'un emplacement dans mon code Je veux montrer l'icône loc.png sur la carte correspondant à ces coordonnées comment je peux accomplir cette tâche? –

+0

L'exécution du programme s'arrête car, dans main.stroyboard, vous avez un IBOutlet connecté au bouton findMe qui n'existe pas dans votre classe de contrôleur. Sauf si vous supprimez la liaison de ce IBOutlet findMe, votre code ne sera pas transmis via les validations d'exécution. –

0

Réponse à votre requête:
Je veux mettre les coordonnées de plus d'un emplacement dans mon code, je veux montrer icône loc.png sur la carte correspondant à ces coordonnées comment je peux accomplir cette tâche?

Voici le code pour ViewController.h

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

 
@interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate> 
 

 
@end

Voici le code pour ViewController.m

#import "ViewController.h" 
 
#import "MyAnnotation.h" 
 
#import <MapKit/MapKit.h> 
 

 
@interface ViewController() 
 

 
@property (strong, nonatomic) IBOutlet MKMapView *myMapView; 
 

 
@end 
 

 
@implementation ViewController 
 

 

 
- (void)viewDidLoad { 
 
    [super viewDidLoad]; 
 

 
    // setup the map view, delegate and current location 
 

 
    [self.myMapView setDelegate:self]; 
 

 
    self.myMapView.mapType = MKMapTypeStandard; 
 

 
    CLLocationCoordinate2D myLocation = CLLocationCoordinate2DMake(25.085130,-77.331428); 
 
    [self.myMapView setCenterCoordinate:myLocation]; 
 

 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(myLocation, 2000, 2000); 
 
    region.center = self.myMapView.centerCoordinate; 
 
    self.myMapView.showsUserLocation = YES; 
 
    [self.myMapView setRegion:region animated:YES]; 
 

 
    [self dropPins]; 
 
} 
 

 
-(void)dropPins { 
 
    NSMutableArray *annotationArray = [[NSMutableArray alloc] init]; 
 

 
    CLLocationCoordinate2D location1 = CLLocationCoordinate2DMake(25.085130, -77.331428); 
 
    MyAnnotation *annotation1 = [[MyAnnotation alloc] initWithCoordinates:location1 image:@"loc.png"]; 
 
    [annotationArray addObject:annotation1]; 
 
    [self.myMapView addAnnotations:annotationArray]; 
 

 
    [annotationArray removeAllObjects]; 
 
    CLLocationCoordinate2D location2 = CLLocationCoordinate2DMake(25.085130, -77.336428); 
 
    MyAnnotation *annotation2 = [[MyAnnotation alloc] initWithCoordinates:location2 image:@"loc.png"]; 
 
    [annotationArray addObject:annotation2]; 
 
    [self.myMapView addAnnotations:annotationArray]; 
 
} 
 

 
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
 
    static NSString *identifier = @"MyLocation"; 
 
    if ([annotation isKindOfClass:[MyAnnotation class]]) 
 
    { 
 
     MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.myMapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
 

 
     if (annotationView == nil) 
 
     { 
 
      annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
 
     } else 
 
     { 
 
      annotationView.annotation = annotation; 
 
     } 
 

 
     annotationView.enabled = YES; 
 
     annotationView.canShowCallout = NO; 
 

 
     if([[(MyAnnotation *)annotationView.annotation image] isEqualToString:@"pin1.png"]) 
 
      annotationView.image = [UIImage imageNamed:@"loc.png"]; 
 

 
     if([[(MyAnnotation *)annotationView.annotation image] isEqualToString:@"pin2.png"]) 
 
      annotationView.image = [UIImage imageNamed:@"loc.png"]; 
 

 
     return annotationView; 
 
    } 
 
    return nil; 
 
} 
 

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

 
@end

Ajouter de nouveaux fichiers MyAnnotation.h/MyAnnotation.m

Voici le code pour MyAnnotation.h

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

 
@interface MyAnnotation : NSObject <MKAnnotation> 
 

 
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 
 
@property (nonatomic, copy, readonly) NSString *image; 
 

 

 
-(id)initWithCoordinates:(CLLocationCoordinate2D) paramCoordinates 
 
        image:(NSString *) paramImage; 
 

 
@end

Voici le code pour MyAnnotation .m

#import "MyAnnotation.h" 
 

 
@implementation MyAnnotation 
 

 
-(id)initWithCoordinates:(CLLocationCoordinate2D)paramCoordinates 
 
        image:(NSString *)paramImage 
 
{ 
 
    self = [super init]; 
 
    if(self != nil) 
 
    { 
 
     _coordinate = paramCoordinates; 
 
     _image = paramImage; 
 
    } 
 
    return (self); 
 
} 
 

 
@end