0
我正試圖加載data.plist字符串數組多邊形下的NSDictionary(例如+ 40.48675,-60.434543)建設。我有6個索引。我不斷收到警告「通過initWithID的參數7:name:code:number:location:description:polygons from incompatible pointer type。」 也繪製多邊形不顯示在地圖上。我錯過了什麼?如何在NSDictionary下加載plist並傳遞字符串Array polygons?
NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
NSArray *array = [[[NSArray alloc] initWithContentsOfFile:path] objectAtIndex:0];
buildings = [[NSMutableArray alloc] init];
for(int i = 0; i < [array count]; i++)
{
NSMutableDictionary *dic = [array objectAtIndex:i];
NSString *buildingID = [dic objectForKey:@"buildingID"];
NSString *name = [dic objectForKey:@"name"];
NSString *code = [dic objectForKey:@"code"];
NSString *number = [dic objectForKey:@"number"];
//NSString *location = [dic objectForKey:@"location"];
NSString *description = [dic objectForKey:@"description"];
//NSArray *components = [location componentsSeparatedByString:@","];
//NSString *latitude = [components objectAtIndex:0];
//NSString *longitude = [components objectAtIndex:1];
NSArray *polygons = [[NSArray alloc] init];
polygons = [dic objectForKey:@"polygons"];
int countPoints = [self.polygons count];
CLLocationCoordinate2D buildingPoly[countPoints];
for (int i = 0; i < countPoints; i++) {
NSArray *splitArrayPoly = [[polygons objectAtIndex:i] componentsSeparatedByString:@","];
buildingPoly[i] = CLLocationCoordinate2DMake([[splitArrayPoly objectAtIndex:0] floatValue], [[splitArrayPoly objectAtIndex:1] floatValue]);
}
NSArray *splitArray = [ [dic objectForKey:@"location"] componentsSeparatedByString:@","];
float latitude = [[splitArray objectAtIndex:0]floatValue];
float longitude = [[splitArray objectAtIndex:1]floatValue];
CLLocation *tempLocation = [[[CLLocation alloc]
initWithLatitude:latitude
longitude:longitude]autorelease];
Building *building = [[[Building alloc] initWithID:[buildingID intValue]
name:name
code:code
number:number
location:tempLocation
description:description
polygons:buildingPoly]autorelease]; //This is where I got warning
//building.polygons = polygons; // delete this when ure done with init
//NSLog(@"building.polygons = %@", building.polygons); // ask teacher about this
[buildings addObject:building];
[dic release];
[building release];
}
然後在不同的類「Building.m」它傳遞多邊形到這裏
- (id)initWithID:(int)b_id
name:(NSString *)b_name
code:(NSString *)b_code
number:(NSString *)b_number
location:(CLLocation *)b_location
description:(NSString *)b_description
polygons:(NSArray *)b_polygons
{
self = [super init];
if (self != nil) {
self.buildingID = b_id;
self.name = b_name;
self.location = b_location;
self.code = b_code;
self.number = b_number;
self.description = b_description;
self.polygons = b_polygons;
}
return self;
}
那麼這個方法應該得到所有多邊形,並使其在地圖上。但它沒有顯示任何東西。
- (MKPolygon *)getPolygons{
int countPoints = [self.polygons count];
CLLocationCoordinate2D building[countPoints];
for (int i = 0; i < countPoints; i++) {
NSArray *splitArray = [[polygons objectAtIndex:i] componentsSeparatedByString:@","];
building[i] = CLLocationCoordinate2DMake([[splitArray objectAtIndex:0] floatValue], [[splitArray objectAtIndex:1] floatValue]);
}
return [MKPolygon polygonWithCoordinates:building count:countPoints];
}
請編輯您的問題。代碼是不可讀的,所以沒有人會麻煩嘗試閱讀它。並且讓你的問題更清楚,因爲我無法確切知道你的問題 – 2011-05-08 18:11:46