在地图视图中加载MKAnnotation时应用程序崩溃

时间:2013-05-11 08:11:38

标签: objective-c ipad ios6 mkmapview mkannotation

在我的应用程序中,我集成了一个视图控制器,如容器(拆分视图)。 Controller视图控制器容器两个视图。细节视图和选择视图(表视图)。

enter image description here

在选择表格单元格时,我需要在MKMap视图中加载MKAnnotation。正常敲击电池时工作正常。如果我们同时从选择表视图中选择单元格(更快地随机选择单元格)应用程序崩溃。我确信崩溃只是由于这个注释代码。这是我的代码。

注释类:

@interface AddressAnnotation : NSObject<MKAnnotation> {
    CLLocationCoordinate2D coordinate;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c;
@end


@implementation AddressAnnotation
@synthesize coordinate;

- (NSString *)subtitle{
    return nil;
}

- (NSString *)title{
    return nil;
}

-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
    coordinate=c;
    return self;
}

@end

在详细视图中添加注释的代码:

detail.h
      AddressAnnotation *addAnnotation;
detail.m
CLLocationCoordinate2D coordinate;

    coordinate.latitude = [self.latitude intValue];
    coordinate.longitude = [self.longitude intValue];
    [self.mapView setUserInteractionEnabled:NO];

   addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:coordinate];
    [self.mapView addAnnotation:addAnnotation];

正如我说它在正常情况下工作正常,如果我们同时选择单元格,应用程序崩溃。指导我解决这个问题。

感谢。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。崩溃是由于在地图视图中加载注释之前切换详细视图控制器。为此,需要在视图消失时将地图视图委托设置为nil。这是我的代码。

- (void)viewDidDisappear:(BOOL)animated
{
     [self.mapView setDelegate:nil];
}
相关问题