Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MapKit注释显示在一个视图控制器中,而不显示在另一个视图控制器中_Ios_Objective C_Mapkit_Mapkitannotation - Fatal编程技术网

Ios MapKit注释显示在一个视图控制器中,而不显示在另一个视图控制器中

Ios MapKit注释显示在一个视图控制器中,而不显示在另一个视图控制器中,ios,objective-c,mapkit,mapkitannotation,Ios,Objective C,Mapkit,Mapkitannotation,在我的浏览视图控制器中,将显示地图工具包注释。 _mapVC = [[CollectionMapViewController alloc] init]; mapVC.collectedLeafArray = [collectionFetchedResultsController fetchedObjects]; mapVC.canShowCallout = YES; mapVC.delegate = self; [mapVC layoutMapView]; [se

在我的浏览视图控制器中,将显示地图工具包注释。

_mapVC = [[CollectionMapViewController alloc] init];
mapVC.collectedLeafArray = [collectionFetchedResultsController fetchedObjects];
    mapVC.canShowCallout = YES;
    mapVC.delegate = self;
    [mapVC layoutMapView];
    [self addChildViewController:mapVC];
    [self.view insertSubview:mapVC.view belowSubview:_userCollectionSortMenu.view];

    [mapVC didMoveToParentViewController:self];
 _mapVC = [[CollectionMapViewController alloc] init];
    _mapVC.collectedLeafArray = [NSArray arrayWithObject:_collectedLeaf];
    _mapVC.delegate = self;
    _mapVC.canShowCallout = NO;
    [_mapVC layoutMapView];

    [self addChildViewController:_mapVC];
    [_scrollView addSubview:_mapVC.view]; 
    [_mapVC didMoveToParentViewController:self];
我设置子视图控制器的方式与设置笔记视图控制器的方式完全相同。但是,它们不会显示注释PIN。

_mapVC = [[CollectionMapViewController alloc] init];
mapVC.collectedLeafArray = [collectionFetchedResultsController fetchedObjects];
    mapVC.canShowCallout = YES;
    mapVC.delegate = self;
    [mapVC layoutMapView];
    [self addChildViewController:mapVC];
    [self.view insertSubview:mapVC.view belowSubview:_userCollectionSortMenu.view];

    [mapVC didMoveToParentViewController:self];
 _mapVC = [[CollectionMapViewController alloc] init];
    _mapVC.collectedLeafArray = [NSArray arrayWithObject:_collectedLeaf];
    _mapVC.delegate = self;
    _mapVC.canShowCallout = NO;
    [_mapVC layoutMapView];

    [self addChildViewController:_mapVC];
    [_scrollView addSubview:_mapVC.view]; 
    [_mapVC didMoveToParentViewController:self];
我知道收集的叶不是零,因为我在设置注释的
CollectionMapViewController
方法中检查纬度:

- (void)layoutMapView
{
    NSMutableArray* leavesWithValidGeotag = [[NSMutableArray alloc] initWithCapacity:[collectedLeafArray count]];

    for (CollectedLeaf* collectedLeaf in collectedLeafArray)
    {
        NSLog(@"latitude: %@", collectedLeaf.latitude);
        if ( ![collectedLeaf.latitude isEqualToString:kGeoLocationNotAvailable] )
        {
            [leavesWithValidGeotag addObject:collectedLeaf];
            LeafAnnotation* annotation = [[LeafAnnotation alloc] initWithLeaf:collectedLeaf];
            [mapView addAnnotation:annotation];
            [annotation release];
        }
    }

    //// Adjust the region

    if([leavesWithValidGeotag count] > 1)
    {
        NSArray* westEastSort = [leavesWithValidGeotag sortedArrayUsingSelector:@selector(longitudeCompare:)];
        CollectedLeaf* eastMostLeaf = [westEastSort objectAtIndex:0];
        CollectedLeaf* westMostLeaf = [westEastSort lastObject];

        NSArray* southNorthSort = [leavesWithValidGeotag sortedArrayUsingSelector:@selector(latitudeCompare:)];
        CollectedLeaf* southMostLeaf = [southNorthSort objectAtIndex:0];
        CollectedLeaf* northMostLeaf = [southNorthSort lastObject];

        CLLocationCoordinate2D center;
        center.longitude = ([westMostLeaf.longitude doubleValue] + [eastMostLeaf.longitude doubleValue]) / 2.0f;
        center.latitude = ([southMostLeaf.latitude doubleValue] + [northMostLeaf.latitude doubleValue]) / 2.0f;

        MKCoordinateSpan span = MKCoordinateSpanMake(1.5 * fabs([northMostLeaf.latitude doubleValue] - [southMostLeaf.latitude doubleValue]),
                                                     1.5 * fabs([westMostLeaf.longitude doubleValue] - [eastMostLeaf.longitude doubleValue]));

        if ( span.latitudeDelta < kMinimumSpan )
        {
            span.latitudeDelta = kMinimumSpan;
        }
        if ( span.longitudeDelta < kMinimumSpan )
        {
            span.longitudeDelta = kMinimumSpan;
        }

        MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
        [mapView setRegion:region];
    }

    else if([leavesWithValidGeotag count] == 1)
    {
        CollectedLeaf* theLeaf = [leavesWithValidGeotag objectAtIndex:0];
        CLLocationCoordinate2D center;
        center.longitude = [theLeaf.longitude doubleValue];
        center.latitude = [theLeaf.latitude doubleValue];
        MKCoordinateSpan span = MKCoordinateSpanMake(kMinimumSpan, kMinimumSpan);
        MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
        [mapView setRegion:region];
    }

    [leavesWithValidGeotag release];
}
-(无效)布局映射视图
{
NSMutableArray*LeaveSwithValidGetAg=[[NSMutableArray alloc]initWithCapacity:[collectedLeafArray count]];
for(CollectedLeaf*CollectedLeaf在CollectedLeaf数组中)
{
NSLog(@“纬度:%@”,collectedLeaf.latitude);
如果(![collectedLeaf.latitude为相等字符串:kGeoLocationNotAvailable])
{
[LeaveSwithValidGetAg添加对象:collectedLeaf];
LeafAnnotation*annotation=[[LeafAnnotation alloc]initWithLeaf:collectedLeaf];
[地图视图添加注释:注释];
[注释发布];
}
}
////调整区域
如果([LeaveSwithValidGetAg计数]>1)
{
NSArray*westEastSort=[LeaveSwithValidGetAg-SortedArray使用选择器:@selector(纵向比较:)];
CollectedLeaf*eastMostLeaf=[westEastSort对象索引:0];
CollectedLeaf*westMostLeaf=[westEastSort lastObject];
NSArray*southNorthSort=[LeaveSwithValidgeToTag SortedArray使用选择器:@selector(latitudeCompare:)];
CollectedLeaf*southMostLeaf=[southNorthSort objectAtIndex:0];
CollectedLeaf*northMostLeaf=[southNorthSort lastObject];
位置协调中心;
center.longitude=([westMostLeaf.longitude doubleValue]+[eastMostLeaf.longitude doubleValue])/2.0f;
中心纬度=([southMostLeaf.latitude doubleValue]+[northMostLeaf.latitude doubleValue])/2.0f;
MKCoordinateSpan span=MKCoordinateSpanMake(1.5*fabs([northMostLeaf.latitude doubleValue]-[southMostLeaf.latitude doubleValue]),
1.5*晶圆厂([westMostLeaf.经度双值]-[eastMostLeaf.经度双值]);
如果(span.latitudeDelta
也许,您需要复制NSArray对象

NSArray *test1 = [NSArray arrayWithObject:_collectedLeaf];
_mapVC.collectedLeafArray = [test1 copy];