【问题标题】:adding disclosre buttons to mapview annotations向地图视图注释添加公开按钮
【发布时间】:2011-04-25 22:27:54
【问题描述】:

我知道它被问过很多次了,但我似乎无法理解。我绘制了地图,添加了注释,我想在注释中添加披露按钮。

我通过从文本文件中拉入,在我的 viewdidload 方法中从数组中添加注释

NSURL *dataUrl = [NSURL URLWithString:@"http://nne.ezadspro.co.uk/cms/testmap.txt"];

NSString *fileString = [NSString stringWithContentsOfURL:dataUrl
                                                encoding:NSUTF8StringEncoding
                                                   error:nil];
int count = 0;
NSScanner *scanner = [NSScanner scannerWithString:fileString];

eventPoints = [[NSMutableArray array] retain];
Locations *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 = [[[Locations 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];
        [eventPoints addObject:event];
    }
    count++;
    if(count == 300) {
        //limit number of events to 300
        break;
    }
}
//UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

[mapView addAnnotations: eventPoints];

这很好用,但就像我说的我想添加按钮,现在我在多个线程中看到人们在谈论该方法 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {

但是无论我用这种方法做什么似乎都不起作用,有人可以帮我看看我是如何让它工作的(它是怎么称呼的?)我不知道

我对此很陌生,所以如果可以的话,让它变得简单,并且尽量不要问太多问题:)

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    mapView:viewForAnnotation: 是一个委托方法,因此您需要将 mapView 的委托属性设置为您的对象(或使用 Interface Builder 进行连接)。您最需要的是:

    mapView.delegate = self;
    

    【讨论】:

      猜你喜欢
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 2023-03-28
      • 1970-01-01
      • 2012-02-27
      • 2017-06-11
      相关资源
      最近更新 更多