Search code examples
iosios6

Counter Stays at Zero


I must be missing something here. I've created counter after counter and they all work, but in this code below the counter i always stays at zero. The mapDelays count correctly shows 18. The idea is that it compares the array value at i against true or false. This is called from another method that plots pins from an airports array (18 airports). One of the items in the array is the 'delay' either true or false. So as I plot the airports I want to see if there is a relay 'true' and if there is, make the pin red instead of green. Yes, I'm a newbie so any pointers would help - specifically, flow and logic I'm obviously missing!

- (MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:
(id<MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[AirportDetails class]]) {
        static NSString *const kPinIdentifier = @"AirportDetails";
        MKPinAnnotationView *view = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:kPinIdentifier];

        if (!view) {
            view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kPinIdentifier];
            view.canShowCallout = YES;
            view.calloutOffset = CGPointMake(-5, 5);
            view.animatesDrop = NO;
        }
        NSLog(@"I am here");
        for (int i = 0; i < self.mapDelays.count; i++) {
            NSLog(@"DelaysCount %i",i);
            NSLog(@" %i",self.mapDelays.count);
            if ([self.mapDelays[i] isEqualToString:@"true"]) {
                view.pinColor = MKPinAnnotationColorRed;
                view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                return view;
            } else
                view.pinColor = MKPinAnnotationColorGreen;
            view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            //}
            return view;
        }
    } 

    return nil;
}

Solution

  • After I change code format I find that at the first for loop of i you have return view; This will stop your for loop. So you have the zero. Next time you should be careful about your coding style. Especially for {}