在5.0模拟器上运行时不会调用MKMapViewDelegate mapView:didUpdateUserLocation:方法,即使在设备设置中给定了所有位置权限。
对于4.3,它工作得很好。
有什么想法吗?
发布于 2011-10-17 02:35:00
在重构到ARC之后,我得到了同样的结果。
首先,我用viewDidLoad编写了以下代码;
CLLocationManager *lm =[[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
[lm startUpdatingLocation];我在de headerfile中执行了以下操作
@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property(nonatomic, strong)CLLocationManager *locationManager;和
@synthesize locationManager;我在viewDidLoad中更改的代码
locationManager =[[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];发布于 2011-10-26 20:15:28
选中"setUserTrackingMode:animated:“和"userTrackingMode”。这两个都是iOS5中的新特性。我遇到了类似的问题,并通过在setUserTrackingMode函数中设置MKUserTrackingModeFollow来修复它。我认为默认的跟踪模式是MKUserTrackingModeNone,并且只调用mapView:didUpdateUserLocation一次。
如果你的问题是mapView:didUpdateUserLocation永远不会被调用,那么看看新的xcode中的选项,在控制台输出的正下方有一个图标,就像ipad中的gps图标,它可以让你模拟一个位置。
发布于 2013-02-13 18:47:38
我知道这是一条古老的线索。不管怎样,我会回答的,这可能也会对其他人有所帮助。
我在iOS 6上也遇到过类似的问题,我可以通过将mapview委托设置为self来解决这个问题。
如下所示:
[mapView setDelegate:self];确保你的ViewController.h的MKMapViewDelegate是这样的:
@interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>https://stackoverflow.com/questions/7765572
复制相似问题