문제

I'm following along with chapter 15 of the Stanford iOS 7 course where MapKit is implemented. When a cell is clicked on in a Core Data Table View Controller (the name given to a controller by the professor), it's supposed to segue to a map view where pins (i.e. annotations) show the location of the photo on a map. The code below is from the controller that organizes photos by photographer and is generating this warning next to the first line of the method in the code below

sending 'nsarray *' to parameter of incompatible type 'id mkannotation '

in XCode, and when I run it, it stops on the first line of the code below and leaves this error message in the console

Photomania[2108:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM coordinate]: unrecognized selector sent to instance 0x9d37df0'

So I understand that a message (the selector) is being sent to an instance that doesn't recognize the message, but I'm not sure what is the incorrect selector and which object doesn't recognize it?

#import "PhotosByPhotographerMapViewController.h"
#import <MapKit/MapKit.h>
#import "Photo.h"

@interface PhotosByPhotographerMapViewController () <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (nonatomic, strong) NSArray *photosByPhotographer;

@end

@implementation PhotosByPhotographerMapViewController

-(void)updateMapViewAnnotations
{

    [self.mapView removeAnnotation: self.mapView.annotations];
    [self.mapView addAnnotations: self.photosByPhotographer];
    [self.mapView showAnnotations: self.photosByPhotographer animated:YES];

}
도움이 되었습니까?

해결책

This line:

[self.mapView removeAnnotation: self.mapView.annotations];

should probably be:

[self.mapView removeAnnotations: self.mapView.annotations];

removeAnnotation: expects a single annotation. removeAnnotations: expects an array of annotations.

This will solve both of your issues.

FYI - never ignore compiler warnings. If your code isn't compiling clean it will likely crash.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top