2
我一直在为此奋斗了几天,我甚至重写了一半的代码尝试另一种方式。mapkit,标注一个注释索引的披露按钮
我有从csv导入我的注释,并放置在贴图和字幕上,我试图徒劳地向披露按钮添加一个标签,以便我可以看到哪一个被挖掘,但有问题,无论值我分配给注解我似乎无法访问它们(如索引)我可以访问标题和副标题,但多数民众赞成它。
如何将指标分配到注释,然后我就可以添加到按钮作为标记,这样我就可以记录水龙头
这里是我的代码
NSURL *dataUrl = [NSURL URLWithString:@"http://nne.ezadspro.co.uk/cms/testmap.txt"];
// URLWithString:@"http://neic.usgs.gov/neis/gis/qed.asc"];
NSString *fileString = [NSString stringWithContentsOfURL:dataUrl
encoding:NSUTF8StringEncoding
error:nil];
int count = 0;
NSScanner *scanner = [NSScanner scannerWithString:fileString];
points = [[NSMutableArray array] retain];
AnnotationData *event;
NSString *line;
NSArray *values;
while ([scanner isAtEnd] == NO) {
[scanner scanUpToString:@"\n" intoString:&line];
//skip the first line
if(count > 0) {
values = [line componentsSeparatedByString:@","];
event = [[[AnnotationData alloc] init] autorelease];
event.latitude = [[values objectAtIndex:5] floatValue];
event.longitude = [[values objectAtIndex:6] floatValue];
event.companyID = [[values objectAtIndex:0]intValue];
event.title = [values objectAtIndex:1];
event.subtitle = [values objectAtIndex:2];
//event.magnitude = [[values objectAtIndex:4] floatValue];
//event.depth = [[values objectAtIndex:5] floatValue];
//NSLog(@"%@",event.companyID);
[points addObject:event];
}
count++;
if(count == 300) {
//limit number of events to 300
break;
}
}
for (int i=0; i<points.count; i++) {
AnnotationData *annData = [points objectAtIndex:i];
coordinate.latitude = annData.latitude;
coordinate.longitude = annData.longitude;
CLLocationCoordinate2D newCoord = {coordinate.latitude, coordinate.longitude};
PlaceAnnotation* annotation = [[PlaceAnnotation alloc] initWithCoordinate:newCoord andID:i];
annotation.mTitle = annData.title;
annotation.mSubtitle = annData.subtitle;
annotation.indexID = i;
//annotation.indexID = [[i]intValue];
[mapView addAnnotation:annotation];
[annotation release];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mV.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[mV dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinAnnotation == nil)
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
//instatiate a detail-disclosure button and set it to appear on right side of annotation
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinAnnotation.rightCalloutAccessoryView = infoButton;
//infoButton.tag =
//[infoButton addTarget:self action:@selector(onMapVenueSelect) forControlEvents:UIControlEventTouchUpInside];
//defaultPinID.rightCalloutAccessoryView = infoButton;
//infoButton.tag = [event indexOfObject:tmpVenueData];
// [defaultPinID release];
}
return pinAnnotation;
[pinAnnotation release];
}
感谢
我已经在这样做,但一旦我尝试在viewForAnnotation方法中添加标签,它只是返回0,每次。是否有你使用NSNumber而不是NSUInteger的原因? – 2010-10-19 10:11:15
你为什么使用标签?我不确定在这种情况下我是否理解标签的要点。只需访问您需要的财产。 NSUInteger会很好,只是例子。 – Nick 2010-10-19 16:01:49
我添加了一个如何通过注释accessorycontroltapped委托方法访问ID的示例。 – Nick 2010-10-19 16:10:53