저는 아이폰 개발을 처음 접했고지도에 주석을 달으려고합니다. 필자는 하드 코드 된 좌표가있는지도에서 3 개의 위치 점을 얻을 수 있었고 이제는 핀을 사용자 정의하려고합니다. 나는 당신이 : -(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {
대리자 메서드를 구현할 필요가 있다는 것을 알고 있습니다.MKMapView 대리자 메서드가 호출되지 않는 이유는 무엇입니까?
나는 굳이 전화를받지 못했습니다. 내가 컨트롤러 구현에 무슨 여기
#import "ArtPiece.h"
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface TestViewController : UIViewController <MKMapViewDelegate> {
MKMapView *mapView;
NSMutableArray *mapAnnotations;
float results_lat[3];
float results_long[3];
NSMutableArray *results_title;
NSMutableArray *Arts;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) NSMutableArray *mapAnnotations;
@end
된다 : 여기
- (void)viewDidLoad {
results_long[0] = -122.477989;
results_lat[0] = 37.810000;
results_long[1] = -122.480000;
results_lat[1] = 37.820000;
results_long[2] = -122.4850000;
results_lat[2] = 37.830000;
self.mapAnnotations = [[NSMutableArray alloc] initWithCapacity:3];
Arts = [[NSMutableArray alloc] initWithCapacity:3];
for(int x = 0; x<3; x++)
{
// creates an ArtPiece object and sets its lat and long
ArtPiece *a = [[ArtPiece alloc] init];
a.longitude = [NSNumber numberWithDouble:results_long[x]];
a.latitude = [NSNumber numberWithDouble:results_lat[x]];
a.title = @"please show up";
// add objects to annotation array
[self.mapAnnotations insertObject:a atIndex:x];
[a release];
}
// center screen on cali area
[self gotoLocation];
for(int x = 0; x<3; x++)
{
[mapView addAnnotations:mapAnnotations];
}
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {
NSLog(@"This is not printing to to console...");
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
그리고 ArtPiece 클래스 구현된다
#import "TestViewController.h"
#import "ArtPiece.h"
#import <MapKit/MapKit.h>
#import <CoreData/CoreData.h>
@implementation ArtPiece
@synthesize title, artist, series, description, latitude, longitude;
- (CLLocationCoordinate2D)coordinate
{
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = [self.latitude doubleValue];
theCoordinate.longitude = [self.longitude doubleValue];
return theCoordinate;
}
@end
여기에 내가 컨트롤러 헤더에있는 것입니다 그것은 아마도 단순한 무언가 일 것입니다. 내 메소드 선언에 문제가 있습니까? 나는 대표자를 틀리게 선언 했는가? 나는 그것을 다시 알 수 없다. 다시 한번 나는이 목적에 매우 새롭다. 어떤 도움을 주셔서 감사합니다.
의견을 보내 주셔서 감사합니다. 내 질문에 ArtPiece 클래스를 포함하도록 편집했습니다. 위도와 경도 데이터 멤버가 설정 한 좌표 프로토콜이 있다고 생각합니다. 내지도에 기본 빨간색 핀이 표시되므로 MKAnnotation 프로토콜을 준수해야한다고 생각합니다. 하지만 아마도 내가 틀렸어? ArtPiece 클래스를보고 다른 아이디어를 주거나 첫 번째 대답을 확인합니까? – Ryan
좋아, 빨간색 핀이 보이면 ArtPiece는 괜찮을거야. 그런 다음 인터페이스 빌더에서 MapView의 델리게이트를 TestViewController의 File Owner에 연결 했습니까? – Anna
IB에서 위임 연결이 정상이면 ArtPiece.h 파일을 게시하십시오. – Anna