简体   繁体   English

mapView:regionDidChangeAnimated:从未调用

[英]mapView:regionDidChangeAnimated: never called

In the storyboard I have a Navigation Controller in Relationship with a View Controller. 在情节提要中,我有一个与视图控制器关联的导航控制器。

The View Controller contains a MKMapView. 视图控制器包含一个MKMapView。

The View Controller is also set, in Identity Inspector -> Custom Class, to be a custom controller: MapViewController. 在Identity Inspector->“自定义类”中,还将View Controller设置为自定义控制器:MapViewController。

This is MapViewController.h 这是MapViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "MarkerAnnotation.h"
#import "MarkerButton.h"
#import "MainMapView.h"

@interface MapViewController : UITableViewController <MKMapViewDelegate, CLLocationManagerDelegate>

@property (weak, nonatomic) IBOutlet MKMapView *localMapView;

@end

localMapView is linked to the MKMapView placed in the ViewController on the storyboard through "Referencing Outlets", and I'm using it already in the code on .m file for things like setting annotations or getting "bounds.origin". localMapView通过“参考出口”链接到放置在情节提要板上的ViewController中的MKMapView,并且我已经在.m文件的代码中使用它来设置注释或获取“ bounds.origin”。

Every time the user moves the map I need to run some lines to update the map. 每次用户移动地图时,我都需要运行一些行来更新地图。 So, I tried to implement mapView:regionDidChangeAnimated: on the .m file, but this is never called. 因此,我尝试在.m文件上实现mapView:regionDidChangeAnimated:,但是从未调用过它。

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    NSLog(@"Region changed");
}

I tried creating a custom subclass of MKMapView implementing on that class the method, but wasn't called either. 我尝试创建一个在该类上实现该方法的MKMapView的自定义子类,但没有被调用。 (you can still see in the imports of .h file, MainMapView.h... I still haven't deleted the import) (您仍然可以在导入的.h文件MainMapView.h中看到...我仍然没有删除导入)

Is there something I'm missing? 有什么我想念的吗? Do I have to set some more connection between the map and the current class? 我是否需要在地图和当前课程之间设置更多连接?

Otherwise, is there another way I can trigger an event every time the map moves? 否则,是否还有另一种方法可以在地图每次移动时触发事件?

When delegate methods don't get called, first thing to check is whether the object's delegate property is set or connected. 当不调用委托方法时,首先要检查的是对象的delegate属性是已设置还是已连接。

(Declaring that a class implements the delegate protocol in the .h file is not the same thing -- that just lets the compiler know what should be expected of the class code implementation so it can provide compile-time warnings.) (声明类在.h文件中实现委托协议不是同一回事–只是让编译器知道应该对类代码实现期望什么,以便它可以提供编译时警告。)

So in addition to the referencing outlet, you must also connect the map view's delegate outlet to File Owner or in code (generally in viewDidLoad) do mapView.delegate = self; 因此,除了引用出口外,还必须将地图视图的委托出口连接到文件所有者,或在代码中(通常在viewDidLoad中)执行mapView.delegate = self; .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM