MKUserTrackingBarButtonItem在放大时崩溃

时间:2013-12-18 23:46:02

标签: ios7 navigation tracking

我正在使用MKUserTrackingBarButtonItem来跟踪用户。使用用户跟踪栏按钮时,我无法设置缩放。所以我试图放大屏幕。 并且应用程序在几个步骤后崩溃。 我有一个坐标附近,我试图用它来跟踪用户相对于坐标。 为什么应用程序崩溃。 有一个更好的方法吗?任何帮助是极大的赞赏。 这是我的代码: -

 -(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];

self.mapView.delegate = self;


_coordinate1.latitude = 29.9431438;
_coordinate1.longitude = -95.5170326;

 self.mapView.showsUserLocation = YES; }


-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];


  MKCoordinateRegion region = [self regionFromLocations:self.currentLoc];

[self displayPoints];

MKCoordinateRegion adjustRegion = [self.mapView regionThatFits:region];

self.mapView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[self.mapView setRegion:adjustRegion animated:YES]; }




- (void)viewDidLoad {

[super viewDidLoad];
 MKUserTrackingBarButtonItem *locateMeButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];



NSArray *toolbarItems = [NSArray arrayWithObjects: locateMeButton,
                         nil];
self.toolBar.items = toolbarItems; }





- (void)viewWillDisappear:(BOOL)animated {

NSLog(@"viewwillDisapear");

[self.mapView setUserTrackingMode:MKUserTrackingModeNone];

[super viewWillDisappear:animated];}


-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
// getting current location
self.currentLoc = userLocation.location.coordinate;

NSLog(@"loc- %f   %f", self.currentLoc.longitude, self.currentLoc.latitude); }

1 个答案:

答案 0 :(得分:0)

在视图消失时删除地图视图解决了问题

- (无效)viewWillDisappear:(BOOL)动画{

[super viewWillDisappear:animated];

self.mapView.delegate = nil;
[self.mapView removeFromSuperview];

}