106th Day As An iOS Developer

February 9, 2016 - 106th Day As An iOS Developer

TUESDAY - We don't have work yesterday, it was a holiday, so I'm going to start a series of blogs and tutorials (hopefully) in Tuesday for this week. I remember telling you here in blog (and I also made a tutorial about it, I'm pretty sure of that) how to refresh all of the annotations in your MKMapView. Well, you just have to delete all of your annotations, using fast enumerations or just make your map's annotation array to nil (not sure about the latter option). What if I wanna remove specific annotations in my map? I learned that I need to make sure that each annotation should be compared or be checked if it belongs to your annotations' class, do I make sense here? Check out this sample code used in our project:
for (AVMapViewAnnotation *annotation in self.mapView.annotations) {
    NSString *currentOpObjectID = [[[AVBookingHandler sharedHandler] currentOperator] objectId];
    
    if([annotation isKindOfClass:[AVMapViewAnnotation class]])
    {
        if(![[annotation.blastieOperator objectId] isEqualToString:currentOpObjectID])
        {
            [self.mapView removeAnnotation:annotation];
        }
        else
        {
            bookedOperatorAnnotation = annotation;
        }
    }
}

Please note that the class AVMapViewAnnotation is a custom class for our project which basically makes the custom annotations in our map. Think about the app GrabTaxi or the Waze, they have custom annotations.

I'm going to cut this post for now, what I really wanted to show you is how to remove or add annotations correctly.

Post a Comment