我是新來的,我把我的頭撞在牆上,所以任何幫助你可以提供將不勝感激。如何讓我的MKMapView註釋顯示出來?
我的應用程序正在下載一系列座標和標題,我將其轉換爲MKAnnotations。我已經實現了MKAnnotation協議不夠好,因爲它停止抱怨說,但這裏的代碼:
Annotator.h:
#import <Foundation/Foundation.h>
#import "MapKit/Mapkit.h"
@interface Annotator : NSObject <MKAnnotation>
+ (Annotator *) createAnnotator:(CLLocationCoordinate2D *)coordinate
withTitle:(NSString *)title
andSubtitle:(NSString *)subtitle;
@property (nonatomic, strong) NSString *myTitle;
@property (nonatomic, strong) NSString *mySubtitle;
@property (nonatomic) CLLocationCoordinate2D *coordinate;
@end
很無聊爲止。這裏的Annotator.m:
#import "Annotator.h"
@implementation Annotator
@synthesize myTitle = _myTitle;
@synthesize mySubtitle = _mySubtitle;
@synthesize coordinate = _coordinate;
+ (Annotator *)createAnnotator:(CLLocationCoordinate2D *)coordinate
withTitle:(NSString *)title
andSubtitle:(NSString *)subtitle
{
Annotator *annotation = [[Annotator alloc] init];
annotation.myTitle = title;
annotation.mySubtitle = subtitle;
annotation.coordinate = coordinate;
return annotation;
}
- (NSString *)title
{
return self.myTitle;
}
- (NSString *)subtitle
{
return self.mySubtitle;
}
@end
現在,我已經得到了最中央視圖控制器上的其他代碼,以便儘快與數據的HTTP請求返回,我遍歷它,創建我MKAnnotation對象,然後爲每一個做到這一點:
[self.territoryMap addAnnotation:locationPin];
...其中self.territoryMap是出口到的MKMapView我拖進我的故事板,並locationPin是MKAnnotation對象我和我上面標註器實現創建。
我看過的一些解決方案已經有了MKMapViewDelegate方法,但在我看來,它們不應該是必需的,因爲我只是在尋找默認行爲。我把一個代表放到了一個代表中,這讓我改變了用戶位置的顏色,但這並不是我所擔心的。
還有什麼我需要做的?我很困惑!感謝您提供的任何幫助!
就在addAnnotation行之前,把'NSLog(@「coord =%f,%f; map =%@」,locationPin.coordinate.latitude,locationPin.coordinate.longitude,self. territoryMap);'。它記錄的座標是什麼(拉特/長褲是否正確)?它爲什麼記錄地圖(是否有任何機會)? – Anna