0
我正在使用MKUserTrackingBarButtonItem來跟蹤用戶。使用用戶跟蹤欄按鈕時,我無法設置縮放。所以我試圖放大屏幕。 並且應用程序在幾個步驟後崩潰。 我有一個座標附近,我想用這個來跟蹤用戶相對於座標。 爲什麼應用程序崩潰。 有沒有更好的方法來做到這一點?任何幫助是極大的讚賞。 這是我的代碼: -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); }
什麼是崩潰錯誤信息? – Anna
令人驚訝的是沒有錯誤信息。當我調試控制轉到main.h @autoreleasepool {...}並停留在一個循環。 – user3117208
你將不得不做一些調試與NSLogs,斷點,逐行逐行代碼,直到你找出什麼行導致崩潰和原因。嘗試從這開始:http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 – Anna