gpt4 book ai didi

iphone - mapkit ,用注释索引标记公开按钮

转载 作者:行者123 更新时间:2023-12-03 20:57:31 27 4
gpt4 key购买 nike

我已经为此苦苦挣扎了几天,我什至重写了一半的代码来尝试另一种方式。

我从 csv 导入了注释,并用图 block 和副标题放置在 map 上,我徒劳地尝试添加一个标签来公开按钮,以便我可以看到点击了哪个按钮,但遇到问题,无论我的值是什么分配给注释我似乎无法访问它们(如索引)我可以访问标题和副标题,但仅此而已。

如何为注释分配索引,然后将其作为标签添加到按钮,以便我可以记录点击

这是我的代码

        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];
}

谢谢

最佳答案

考虑使用 MKAnnotation 协议(protocol)并存储您需要的 ID 或数据明智的对象。

起始点标题可能是这样的:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>


@interface YourFancyAnnotationClass : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSNumber *companyID;
}

@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle;
@property(nonatomic, copy) NSNumber *companyID;



@end




Then in your delegate do something like this...

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped:");
YourFancyAnnotationClass *tappedSite = (SiteAnnotation *)[view annotation];
NSNumber *companyIDThatWasClickedExample = [tappedSite companyID];

等等...

关于iphone - mapkit ,用注释索引标记公开按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3966812/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com