简体   繁体   English

UICollectionViewCell中的MapView无法正常工作

[英]MapView inside UICollectionViewCell not functioning

I'm working with the sticky header flow layout ( https://github.com/jamztang/CSStickyHeaderFlowLayout ) on my project, but am running into trouble with the mapview in the header. 我在我的项目上使用粘性标头流布局( https://github.com/jamztang/CSStickyHeaderFlowLayout ),但是在标头中使用mapview遇到麻烦。 The collection view header is a my custom class HeaderMapViewCell that subclasses UICollectionViewCell and has an IBOutlet to an MKMapView , but it doesn't display any annotations or fire any actions for that matter, even though it's properties do change (when i print them in the debugger). 集合视UICollectionViewCell头是我的自定义类HeaderMapViewCell ,它是UICollectionViewCell子类,并且具有IBOutlet到MKMapView ,但是它不会显示任何注释或触发任何操作,即使它的属性确实发生了变化(当我在调试器)。

Basically this is my setup 基本上这是我的设置

UICollectionViewController -> CollectionView -> HeaderMapViewCell -> MapView UICollectionViewController-> CollectionView-> HeaderMapViewCell-> MapView

在此处输入图片说明

Also for example here: 另外例如这里:

-(IBAction)changeData:(UISegmentedControl*)sender{
    if (_mapView.mapType == MKMapTypeStandard)
        [_mapView setMapType:MKMapTypeSatellite];
    else
        [_mapView setMapType:MKMapTypeStandard];
    if(sender.selectedSegmentIndex==0)
        _displayStudents = YES;
    else
        _displayStudents = NO;
    [self.collectionView reloadData];

}

When i fire this method, nothing on the map changes, but when i put a breakpoint, the mapview's property does indeed change, just never displays anything visually! 当我触发该方法时,地图上的任何内容都没有改变,但是当我放置一个断点时,mapview的属性确实发生了改变,只是从不直观地显示任何内容!

The View controllers mapview delegate methods get fired partially. View控制器的mapview委托方法会部分触发。 RegionDidChangeAnimated gets fired once on loading, then when i zoom in it doens't get fired. RegionDidChangeAnimated在加载时被触发一次,然后当我放大时不会被触发。 On the other hand, viewForAnnotation does get called and returns the correct object, but never displays anything. 另一方面,viewForAnnotation确实会被调用并返回正确的对象,但从不显示任何内容。 I'm doing something wrong with the mapview, just not sure what. 我在mapview上做错了,只是不确定是什么。 Let me know if you have an idea, or if you need me to post more code or anything! 让我知道您是否有想法,或者是否需要我发布更多代码或其他内容! Thanks! 谢谢!

Check this method 检查此方法

[mapView addAnnotation:YourMapAnnotation]; [mapView addAnnotation:YourMapAnnotation];

Where did you call this method? 您在哪里调用此方法?

You can put it in didUpdateLocation(locationManager)/didUpdateUserLocation(mapView) or viewDidLoad method. 您可以将其放在didUpdateLocation(locationManager)/ didUpdateUserLocation(mapView)或viewDidLoad方法中。

And if your mapview use iOS8 later, you need to check authorization through locationManger 而且,如果您的mapview以后使用iOS8,则需要通过locationManger检查授权

// ios8

if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){

    [self.locationManager requestWhenInUseAuthorization];

    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if(status == kCLAuthorizationStatusAuthorizedWhenInUse){
        self.mapView.showsUserLocation = YES;
    }
}else{

    self.mapView.showsUserLocation = YES;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM