こんにちは、注釈オブジェクトを含む NSMutableArray があります。次のコードでは注釈が追加されません。
.h には
@property (retain, nonatomic) MarketsDataController *marketList;
.m にはあります (注釈の追加は機能しません。マップには何も表示されません)
_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];
}
< MKAnnotation > を実装する注釈オブジェクトの配列を追加するにはどうすればよいですか? エラーは発生せず、注釈は表示されません。