1

MKMapview で 2 つの注釈ピンの間にパスを追加する必要があります。iOS 5以前では問題ないのですが、iOS 6でアプリを起動しようとすると、驚くほどアプリが終了してしまいます。以下は私のコードです。私のコードに修正がある場合は、私に提案してください。

1.だから私の質問は、アプリケーションのクラッシュを解決できるように、次のコードでメモリを決定する最良の方法を提案することです。

- (void)viewDidLoad 
{
NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoints:pathArray mapView:_mapView];
[_mapView addAnnotation:annotation];
        [annotation release];
        [pathArray removeAllObjects];
}



- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id  <MKAnnotation>)annotation
{
    NSLog(@"%s",__FUNCTION__);
if ([annotation isKindOfClass:[NVPolylineAnnotation class]]) 
{
    NSLog(@"=========ANOTATION=========NVPolylineAnnotationView START");

    //ann=[ann initWithAnnotation:annotation mapView:_mapView];
    NVPolylineAnnotationView *ann=[[NVPolylineAnnotationView alloc] init];
    return [[ann initWithAnnotation:annotation mapView:_mapView]     autorelease];//[[[NVPolylineAnnotationView alloc] initWithAnnotation:annotation    mapView:_mapView] autorelease];

}
else if([annotation isKindOfClass:[MapViewAnnotation class]])
   {

        MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]     initWithAnnotation:annotation reuseIdentifier:@"pointers"] ;
//      annView.rightCalloutAccessoryView = [UIButton buttonWithType:    UIButtonTypeDetailDisclosure];
       annView.animatesDrop=NO;
       annView.canShowCallout = TRUE;
      return [annView autorelease];
}
   else if([annotation isKindOfClass:[PlacePin class]])
   {
       {
        MKPinAnnotationView *pinView = nil; 
        if(annotation != mapView.userLocation) 
           {
            static NSString *defaultPinID = @"com.invasivecode.pin";
            pinView = (MKPinAnnotationView *)[mapView    dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
            if ( pinView == nil ) 
                pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation    reuseIdentifier:defaultPinID] autorelease];
            pinView.pinColor = MKPinAnnotationColorGreen;
            pinView.canShowCallout = YES;
            pinView.animatesDrop = NO;
            } 
            else {
            [mapView.userLocation setTitle:@"I am here"];
           }
        return pinView;
       }
}

return nil;
}


 - (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views 
 {

   NSLog(@"%s",__FUNCTION__);

// fixes that some marker are behind the polyline
    for (int i=0; i<[views count]; i++) 
    {
    MKAnnotationView *view = [views objectAtIndex:i];
    if ([view isKindOfClass:[NVPolylineAnnotationView class]]) 
    {
        [[view superview] sendSubviewToBack:view];

        /* In iOS version above 4.0 we need to update the polyline view     after it
         has been added to the mapview and it ready to be displayed. */
        NSString *reqSysVer = @"4.0";
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
        if ([currSysVer compare:reqSysVer options:NSNumericSearch] !=     NSOrderedAscending) 
        {
            [self updatePolylineAnnotationView];
        }
    }
}
NSLog(@"----------didAddAnnotationViews");
 }

- (void)updatePolylineAnnotationView 
{
NSLog(@"%s",__FUNCTION__);



 MKAnnotationView *annotationView = [views objectAtIndex:0];
 id <MKAnnotation> mp = [annotationView annotation];
 [mapView selectAnnotation:mp animated:NO];
 */
for (NSObject *a in [_mapView annotations]) 
{
    if ([a isKindOfClass:[NVPolylineAnnotation class]]) 
    {
        NVPolylineAnnotation *polyline = (NVPolylineAnnotation *)a;

        NSObject *pv = (NSObject *)[_mapView viewForAnnotation:polyline];
        if ([pv isKindOfClass:[NVPolylineAnnotationView class]]) 
        {
            NVPolylineAnnotationView *polylineView =
            (NVPolylineAnnotationView *)[_mapView viewForAnnotation:polyline];



            [polylineView regionChanged];

        }
    }       
}
}
4

0 に答える 0