我试图在swift上使用JPSThumbnail加载我的注释。由于某种原因下面的代码加载时,它会使用通常的红色引脚加载我的注释。我对目标C没有任何线索所以我不知道该怎么办?我的代码中缺少什么,我是否追加到数组? JPSThumnail Github
JPSThumbnailAnnotation:
+ (instancetype)annotationWithThumbnail:(JPSThumbnail *)thumbnail {
return [[self alloc] initWithThumbnail:thumbnail];
}
- (id)initWithThumbnail:(JPSThumbnail *)thumbnail {
self = [super init];
if (self) {
_coordinate = thumbnail.coordinate;
_thumbnail = thumbnail;
}
return self;
}
- (MKAnnotationView *)annotationViewInMap:(MKMapView *)mapView {
if (!self.view) {
self.view = (JPSThumbnailAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:kJPSThumbnailAnnotationViewReuseID];
if (!self.view) self.view = [[JPSThumbnailAnnotationView alloc] initWithAnnotation:self];
} else {
self.view.annotation = self;
}
[self updateThumbnail:self.thumbnail animated:NO];
return self.view;
}
- (void)updateThumbnail:(JPSThumbnail *)thumbnail animated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:0.33f animations:^{
_coordinate = thumbnail.coordinate; // use ivar to avoid triggering setter
}];
} else {
_coordinate = thumbnail.coordinate; // use ivar to avoid triggering setter
}
[self.view updateWithThumbnail:thumbnail];
}
My Swift Code:
func annotations() -> [JPSThumbnailAnnotation] {
var annotations: [JPSThumbnailAnnotation] = []
let pointData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("1000", ofType: "geojson")!)
let points = NSJSONSerialization.JSONObjectWithData(pointData!,
options: nil,
error: nil) as! NSDictionary
for point in points["glimps"] as! NSArray {
var a = JPSThumbnail()
a.image = UIImage(named: "empire.jpg")
a.title = "Empire State Building"
a.subtitle = "NYC Landmark"
var lat = (point as! NSDictionary)["latitude"] as! CLLocationDegrees
var lon = (point as! NSDictionary)["longitude"] as! CLLocationDegrees
a.coordinate = CLLocationCoordinate2DMake(lat, lon)
a.disclosureBlock = { println("selected Empire") }
var a1: JPSThumbnailAnnotation = JPSThumbnailAnnotation(thumbnail: a)
annotations.append(a1)
}
return annotations
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
return (annotation as? JPSThumbnailAnnotationProtocol)?.annotationViewInMap(mapView)
}