gpt4 book ai didi

ios: addAnnotations 到 mapView 不工作

转载 作者:行者123 更新时间:2023-11-28 22:35:45 25 4
gpt4 key购买 nike

您好,我有一个带有注释对象的 NSMutableArray,下面的代码不会添加注释:

在 .h 中我有

     @property (retain, nonatomic) MarketsDataController *marketList;

在 .m 中我有(添加注释不起作用。 map 上没有显示任何内容)

    _marketList = [_marketService.marketsDataController retain];
NSLog(@"%@!!!", [_marketList objectInListAtIndex:0].title);
[mapView addAnnotation:[_marketList objectInListAtIndex:0]];
[mapView addAnnotation:[_marketList objectInListAtIndex:1]];
[mapView addAnnotation:[_marketList objectInListAtIndex:2]];

MarketsListDataController 看起来像这样:

    #import "MarketsDataController.h"

//The following interface is used for private methods
@interface MarketsDataController ()
- (void)initializeMarketsList;
@end

@implementation MarketsDataController

//Set initial values for instance variables
- (id)init {
NSLog(@"init MarketsDataController");
if (self = [super init]) {
[self initializeMarketsList];
return self;
}
return nil;
}

- (void)initializeMarketsList{
NSMutableArray *marketsList = [[NSMutableArray alloc] init]; //Initialize the product list
_marketsList = marketsList; //Set the markets list to the markets list
}

//Return the number of products
- (NSUInteger)countOfList {
return [_marketsList count];
}

//Return a product within the list
- (MapAnnotation *)objectInListAtIndex:(NSUInteger)theIndex {
return [_marketsList objectAtIndex:theIndex];
}

- (void)addAnnotationToList:(MapAnnotation *)mapAnnotation{
NSLog(@"Adding market");
[_marketsList addObject:mapAnnotation];
}

- (void)dealloc {
NSLog(@"DEALLOC MarketsDataController");
[_marketsList release];
[super dealloc];

}

@end

MapAnnotation .m 看起来像:

#import "MapAnnotation.h"

@implementation MapAnnotation

@synthesize coordinate, title, subtitle;

- (id)init{
CLLocationCoordinate2D location;
location.latitude = 0;
location.longitude = 0;
return [self initWithCoordinate:coordinate title:nil subtitle:nil];
}

- (id)initWithCoordinate:(CLLocationCoordinate2D) c title:(NSString *)t subtitle:(NSString *)st{
self = [super init];
coordinate = c;
title = [t retain];
subtitle = [st retain];
return self;
}

- (void) dealloc{
[title release];
[subtitle release];
[super dealloc];
}

@end

我创建它们并将它们添加到另一个类中,例如:

if (![latitude isEqual:[NSNull null]] && ![longitude isEqual:[NSNull null]]) {
NSLog(@"%d", i);
NSLog(@"%@", title);
CLLocationCoordinate2D coordinate;
coordinate.longitude = [latitude doubleValue];
coordinate.longitude = [longitude doubleValue];
[self buildMarketsList:coordinate title:title subtitle:@""]; //build the browse list product

}

方法如下:

- (void)buildMarketsList:(CLLocationCoordinate2D)c title:(NSString *)t subtitle:(NSString *)st{
MapAnnotation *mapAnnotation = [[MapAnnotation alloc]initWithCoordinate:c title:t subtitle:st];
[_marketsDataController addAnnotationToList:mapAnnotation];
[mapAnnotation release];
}

如何添加一个实现 的注释对象数组?我没有收到任何错误,也不会显示任何注释。

最佳答案

发现问题:

改变:

                coordinate.longitude = [latitude doubleValue];
coordinate.longitude = [longitude doubleValue];

收件人:

                coordinate.latitude = [latitude doubleValue];
coordinate.longitude = [longitude doubleValue];

关于ios: addAnnotations 到 mapView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16117281/

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