将公开按钮添加到mapview注释

时间:2010-10-15 12:52:01

标签: iphone objective-c

我知道它曾经被问过很多次,但我似乎无法得到它。我绘制了地图,添加了注释,并且我想在注释中添加公开按钮。

我通过从文本文件中提取来在我的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 {

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

我对此相当陌生,所以如果你可以做到这一点很简单,并且尽量不要问太多问题:)

1 个答案:

答案 0 :(得分:1)

mapView:viewForAnnotation:是委托方法,因此您需要将mapView的委托属性设置为您的对象(或使用Interface Builder建立连接)。最有可能的是:

mapView.delegate = self;