我遇到这种情况,当我缩小地图时我的应用程序崩溃了。
问题出现是因为我添加了大量注释。请看下面的代码:
- (void) plotUsersInMap
{
for (id<MKAnnotation> annotation in self.mapView.annotations) {
[self.mapView removeAnnotation:annotation];
}
NSUInteger count = //get total count
NSLog(@"count * %d", count);
for (int i = 0; i < count; i++)
{
NSNumber *latitude = //get latitude from json
NSNumber *longitude = //get longitude from json
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude.doubleValue;
coordinate.longitude = longitude.doubleValue;
@autoreleasepool {
MyLocation *annotation = [[MyLocation alloc] initWithName:@"test" coordinate:coordinate QuestionId:nil];
//annotations are added
[self.mapView addAnnotation:annotation];
}
}
}
这里我试图添加超过400个引脚,我认为这是引起崩溃的原因[可能是内存泄漏!]。我想知道在缩小时是否有任何方法可以逐个添加引脚?
在初始阶段映射,没有任何问题:
当我缩小时: