1

我创建了一个运行 6.1 版的 iPhone 应用程序。在我的一个视图中,我正在使用包含注释针的地图视图,缩放到位置。

如果首先打开了所有其他视图并且地图视图没有崩溃,则该应用程序运行良好。但是,如果我打开应用程序并直接使用 mapview 视图控制器,应用程序会崩溃?

此外,该应用程序仅在我的 iPhone 4S 设备上崩溃,而不是在控制器中???

任何人都可以帮助我吗?

此致。

这是我的地图视图代码:

    @interface VisPaaKortViewController ()

@end

@implementation VisPaaKortViewController
@synthesize mapView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.mapView.delegate = self;
    mapView.showsUserLocation = YES;




    // Do any additional setup after loading the view.


    // Create a view of the standard size at the top of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

    // Specify the ad's "unit identifier". This is your AdMob Publisher ID.
    bannerView_.adUnitID = @"my_publisher_id";

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];


    //Placement of banner
    [bannerView_ setFrame:CGRectMake(0,
                                     362,
                                     bannerView_.bounds.size.width,
                                     bannerView_.bounds.size.height)];



    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:[GADRequest request]];


}


-(void) viewWillAppear:(BOOL)animated {
    [self performSelector:@selector(zoomInToMyLocation)
               withObject:nil
               afterDelay:0];
}





- (void)zoomInToMyLocation
{


    CLLocationCoordinate2D location;
    location.latitude = (double) 59.778747;
    location.longitude = (double) 9.292349;



    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:NO];


    // Add an annotation
    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
    point.coordinate = location;
    point.title = @"Text";
    point.subtitle = @"Text";

    [self.mapView addAnnotation:point];
    [self.mapView selectAnnotation:[[self.mapView annotations] objectAtIndex:0] animated:YES];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
4

1 回答 1

0

由于您没有提供太多细节,我不得不猜测。我假设您使用 ARC,我会尝试添加self.mapView.delegate = nil;到您的 dealloc 方法中。

- (void)dealloc {
    self.mapView.delegate = nil;
}

MKMapViews delegate 是声明的assign,而不是声明weak的,这意味着当 viewController 已经被释放时,仍然可以引用委托。

如果你不使用 ARC,你仍然应该在你的 dealloc 中将 mapView.delegate 设为 nil。

于 2013-09-05T14:35:24.373 回答