我对MKPointAnnotation
有疑问。我想像这样创建我的iPhone应用程序:
NSMutableArray
。所以,我的问题是,如何在每个引脚上显示描述?
这是我的代码:
NSMutableArray *points = [[NSMutableArray alloc] init];
for(int i=0; i < [dataTable count]; i++) {
MKPointAnnotation *point =[[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate;
coordinate.latitude = [[[dataTable objectAtIndex:i] objectForKey:@"latitude"] floatValue];
coordinate.longitude = [[[dataTable objectAtIndex:i] objectForKey:@"longitude"] floatValue];
[point setCoordinate:coordinate];
[point setTitle:[[dataTable objectAtIndex:i] objectForKey:@"name"]]; //-- name of pin
[points addObject:point];
}
[map addAnnotations:points];
答案 0 :(得分:0)
我会在我自己的班级中采用MKAnnotation协议,并简单地覆盖
- (NSString) title
并实施
- (CLLocationCoordinate2D) coordinate {
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = self.latitude;
theCoordinate.longitude = self.longitude;
return theCoordinate;
}
我的班级也会有一个初始化程序,它可以获取所需的所有数据(来自你提到的数组)
- (id) initWithTitle:(NSString *)title_ andLatitude:(CLLocationDegrees)latitude_ andLongitude:(CLLocationDegrees)longitude_;
迭代时,我会创建自己的对象,然后将它们添加到注释集合中。
干杯...