新的PList检索代码阻止MKMapView委托方法被调用(iOS)

时间:2011-11-21 17:54:50

标签: ios xcode annotations plist android-mapview

我添加了一个plist数据库来存储MKMapView中注释的信息。一旦我实现了代码来获取信息,我的委托方法就不再被调用了。

我添加的代码是:

- (void)viewDidLoad
{
    NSMutableArray *annotations = [[NSMutableArray alloc]init];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"MillersStores" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *anns = [dict objectForKey:@"Root"];
    for(int i = 0; i < [anns count]; i++) {
        float realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] floatValue];
        float realLongitude = [[[anns objectAtIndex:i] objectForKey:@"Longitude"] floatValue];

        MillersLocations *myAnnotation = [[MillersLocations alloc] init];
        CLLocationCoordinate2D theCoordinate;
        theCoordinate.latitude = realLatitude;
        theCoordinate.longitude = realLongitude;
        myAnnotation.coordinate = theCoordinate;
        myAnnotation.title = [[anns objectAtIndex:i] objectForKey:@"Title"];
        myAnnotation.subtitle = [[anns objectAtIndex:i] objectForKey:@"Address"];
        [mapView addAnnotation:myAnnotation];
        [annotations addObject:myAnnotation];
        [myAnnotation release];
    }
}

这是不再被调用的委托方法之一:

- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    MKPinAnnotationView *pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
    pinView.pinColor = MKPinAnnotationColorRed;
    pinView.animatesDrop = YES;
    pinView.canShowCallout = YES;

    UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MillersAnnotation.png"]];
    pinView.leftCalloutAccessoryView = leftIconView;

    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.rightCalloutAccessoryView = rightButton;
    return pinView;
}

我还有另一个委托方法,它也放大了未被调用的用户位置,以及不再被调用的calloutAccessoryControlTapped方法。

我知道它与新代码有关,但是我对如何调试它感到困惑,因为它没有给我错误而且我无法记录它,因为整个方法甚至都没有被调用。当我摆脱新代码时,旧代码工作得很好......新代码中的代码是什么否定了旧代码?

1 个答案:

答案 0 :(得分:1)

听起来好像没有设置地图视图的delegate属性。

旧代码是否包含此行:

mapView.delegate = self;

将其添加到viewDidLoad,或者在IB中,将地图视图的delegate插座连接到文件所有者。