我正在开发iOS应用程序,当我运行应用程序时我的应用程序。 App Run完美。但数组长度不计入每个。如何计算每个数组的长度。提前致谢。NSArrayI objectAtIndex:]:索引7超越边界[0 .. 6]
这是错误..
'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 7 beyond bounds [0 .. 6]'
代码
- (void)viewDidLoad {
[super viewDidLoad];
count = 0;
marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.snippet = @"Jalandhar";
marker.map = mapView;
self.view = mapView;
timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(updateLocation:) userInfo:nil repeats:YES];
}
- (void)updateLocation:(NSTimer *)timer {
[mapView clear];
NSMutableArray *longitute = [[NSMutableArray alloc]init];
NSDictionary *latLongDict = @{@"lat": @[@"31.3062", @"31.3107",@"31.3102",@"31.3194",@"31.3312",@"29.9083",@"31.2941",],@"long": @[@"75.5935", @"75.6061",@"75.6117",@"75.5845",@"75.5908",@"75.7299",@"75.5844",]};
[longitute addObject:latLongDict];
for (NSDictionary *dic in longitute) {
NSString *val = [[dic valueForKey:@"lat"]objectAtIndex:count];
NSString *value = [[dic valueForKey:@"long"]objectAtIndex:count];
NSLog(@"%@",val);
NSLog(@"%@",value);
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat: 2.0] forKey:kCATransactionAnimationDuration];
CLLocationCoordinate2D center;
center.latitude=[val doubleValue];
center.longitude=[value doubleValue];
marker = [[GMSMarker alloc] init];
marker.position = center;
marker.map = mapView;
self.view = mapView;
[CATransaction commit];
count++;
}
}
是最后的代码或部分代码在例外? – Vishnuvardhan
每当您的计时器触发时,您会增加'count',并且当计数超过阵列的大小时,您不会停止计时器或重置计数 – Paulw11