MKMapView不调用委托方法

MKMapView不调用委托方法

本文介绍了MKMapView不调用委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UIViewController中,我将MKMapView添加到控制器控制的视图中。

In a UIViewController I add a MKMapView to the view controlled by the controller.

- (void)viewDidLoad {
[super viewDidLoad];
CGRect rect = CGRectMake(0, 0, 460, 320);
map = [[MKMapView alloc] initWithFrame:rect];
map.delegate = self;
[self.view addSubview:map];
 }

稍后在控制器中我有

- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
     NSLog(@"done.");
}

完成永不打印。没有其他委托方法被调用像mapView:viewForAnnotation:我在另一个应用程序中使用MKMapView,但这似乎发生在我制作的任何新应用程序上。有没有其他人看到过这种行为?

Done never gets printed. None of the other delegate methods get called either like mapView:viewForAnnotation: I use a MKMapView in an another app, but this seems to happen on any new application I make. Has anyone else seen this behavior?

编辑:

问题似乎是当UIViewController成为委托时MKMapView,NSObject的直接子类似乎工作正常。我可以像这样解决这个问题,因为我之前已经完成了这件事,看起来仍然很奇怪。

The problem seems to be when UIViewController is made the delegate of the MKMapView, a direct subclass of NSObject seems to work okay. I can work around like this, still seems very odd since I've done it before.

推荐答案

我遇到了完全相同的问题:我已经分配了< MKMapViewDeledate>到我的控制器,并将委托链接到Interface Builder中的文件所有者,但仍然没有调用我实现的委托方法。

I had the exact same problem: I had assigned < MKMapViewDeledate> to my controller, and linked the delegate to "File owner" in Interface Builder, but still my implemented delegate methods were not called.

原因是因为iOS 4,缓存地图,每当应用程序显示缓存的地图时,不会调用诸如mapViewDidFinishLoadingMap之类的方法。重置模拟器中的内容和设置会清除缓存的地图,从而解决问题。

The reason is that since iOS 4, maps are cached, and whenever an app display a cached map then methods such as "mapViewDidFinishLoadingMap" are not called. Resetting "contents and settings" in the simulator clears the cached maps and therefore solves the issue.

这篇关于MKMapView不调用委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 07:32