0

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. 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).

Basically this is my setup

UICollectionViewController -> CollectionView -> HeaderMapViewCell -> MapView

enter image description here

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!

The View controllers mapview delegate methods get fired partially. RegionDidChangeAnimated gets fired once on loading, then when i zoom in it doens't get fired. On the other hand, viewForAnnotation does get called and returns the correct object, but never displays anything. I'm doing something wrong with the mapview, just not sure what. Let me know if you have an idea, or if you need me to post more code or anything! Thanks!

royherma
  • 4,095
  • 1
  • 31
  • 42

1 Answers1

0

Check this method

[mapView addAnnotation:YourMapAnnotation];

Where did you call this method?

You can put it in didUpdateLocation(locationManager)/didUpdateUserLocation(mapView) or viewDidLoad method.

And if your mapview use iOS8 later, you need to check authorization through 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;

}
sangjoon moon
  • 720
  • 7
  • 8