trucksArray
我在 viewDidLoad 中声明的数组收到未使用的变量警告。我不明白为什么,因为我在viewController.m
.
我对目标 c 非常陌生,所以如果这是一个非常简单的问题,我提前道歉。
以下是方法:
- (void)viewDidLoad
{
[super viewDidLoad];
TruckLocation *a1 = [[TruckLocation alloc] initWithName:@"test truck 1" address:@"41 Truck Avenue, Provo, Utah" coordinate:CLLocationCoordinate2DMake(40.300828, 111.663802)];
TruckLocation *a2 = [[TruckLocation alloc] initWithName:@"test truck 2" address:@"6 Truck street, Provo, Utah" coordinate:CLLocationCoordinate2DMake(40.300826, 111.663801)];
NSMutableArray* trucksArray =[NSMutableArray arrayWithObjects: a1, a2, nil];
}
以及我使用数组的方法:
- (void)plotTruckPositions:(NSData *)responseData {
for (id<MKAnnotation> annotation in _mapView.annotations) {
[_mapView removeAnnotation:annotation];
}
NSDictionary *root = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSMutableArray *trucksArray = [root objectForKey:@"trucksArray"];
for (NSArray *row in trucksArray) {
NSNumber * latitude = [row objectAtIndex:1];
NSNumber * longitude = [row objectAtIndex:2];
NSString * truckDescription = [row objectAtIndex:2];
NSString * address = [row objectAtIndex:3];
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude.doubleValue;
coordinate.longitude = longitude.doubleValue;
TruckLocation *annotation = [[TruckLocation alloc] initWithName:truckDescription address:address coordinate:coordinate] ;
[_mapView addAnnotation:annotation];
}
}