私はIOSアプリケーションを開発しています。アプリは完璧に走ります。しかし、配列の長さはFor eachでカウントされません。それぞれの配列の長さを数える方法。前もって感謝します。NSArrayI objectAtIndex:]:インデックス7の境界を超えて[0 .. 6]
これはエラー..ですupdateLocation
メソッドを呼び出します
'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'をインクリメントし、タイマーを止めたり、配列のサイズを超えたときに' count'をリセットすることはありません – Paulw11