0
我正在使用下面的代碼來顯示對象的位置。Mapkit問題
- (void)viewDidLoad {
[super viewDidLoad];
[self selectData];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate1 = [location coordinate];
//NSString *latitude = [NSString stringWithFormat:@"%f", coordinate1.latitude];
//NSString *longitude = [NSString stringWithFormat:@"%f", coordinate1.longitude];
mapView.showsUserLocation=YES;
mapView.delegate=self;
//MKMapView *mapView = (MKMapView*)self.view;
CLLocationCoordinate2D coordinate;
coordinate.latitude = coordinate1.latitude;
coordinate.longitude =coordinate1.longitude;
//mapView.region = ;
[mapView setRegion:MKCoordinateRegionMakeWithDistance(coordinate, 2000, 2000)];
NSUInteger count = 1;
[self setTitle:[NSString stringWithFormat:@"%i Memories",[memoryArray count]]];
for(int i = 0; i < [memoryArray count]; i++) {
MemoryData *m=[memoryArray objectAtIndex:i];
//CGFloat latDelta = rand()*.035/RAND_MAX -.02;
//CGFloat longDelta = rand()*.03/RAND_MAX -.015;
coordinate.latitude=[m.lat floatValue];
coordinate.longitude=[m.lon floatValue];
CLLocationCoordinate2D newCoord = {coordinate.latitude, coordinate.longitude};
MapDemoAnnotation* annotation = [[MapDemoAnnotation alloc]initWithCoordinate:newCoord andID:count++];
[annotation setMemoryData:m];
[annotation setTag:i];
[mapView addAnnotation:annotation];
[annotation release];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if(pinView == nil) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
pinView.pinColor = MKPinAnnotationColorRed;
int t=((MapDemoAnnotation*)annotation).tag ;
NSLog(@"Tag is %i ",t);
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
UIImageView *pinImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, 34, 34)];
UIImage *pinImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo" ofType:@"JPG"]];
pinImageView.image = pinImage;
//[pinImage release];
//[pinView addSubview:pinImageView];
//[pinImageView release];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
btn.tag = t;
pinView.rightCalloutAccessoryView = btn;
//pinView.rightCalloutAccessoryView=pinImageView;
} else {
pinView.annotation = annotation;
}
return pinView;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
ViewItemList *list=[[ViewItemList alloc]init];
MemoryData *m=[memoryArray objectAtIndex:control.tag];
[list setMemoryData:m];
[self.navigationController pushViewController:list animated:YES];
}
如果我在iPod上測試它工作正常。 但它我測試iPhone或模擬器上它顯示以下錯誤。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocation tag]: unrecognized selector sent to instance 0xac20da0'
請幫
在哪一行你會發生崩潰? – Mundi
int t =((MapDemoAnnotation *)註解).tag; 看到我想識別不同的標註,例如當我點擊一個它應該去控制器,如果我點擊第二它應該去這樣的控制器B. .. – Mario
多數民衆贊成那是爲什麼在MapDemoAnnotation – Mario