2017-07-03 6 views
1

私はクリックしたときに新しいviewControllerに移動する詳細情報を含むアノテーションを持つmapViewを持っています。次に、ユーザーが詳細の開示からmapViewに戻ることを選択すると、mapViewに、詳細開示をクリックする前にユーザーが持っていたのと同じビューを表示します。以下は私がこれまで設定したコードですが、ユーザーが詳細情報の開示からクリックすると地図がズームアウトします。以前のビューを再作成する方法がわかりません。Swift 3.0 Map Previous MapViewに戻る

詳細ディスクロージャーVC:

// here by segueing, I want to communicate to the MapView VC that the map should remain the same 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if (segue.identifier == "backButtonTapped") 
    { 
     let destinationVC = segue.destination as! TabBarVC 
     mapStatus = "wentBack" 
     print("The value of mapStatus after seguing is \(mapStatus)") 
     destinationVC.selectedIndex = 1 

    } 

} 

のMapView VC:

override func viewDidAppear(_ animated: Bool) { 
    // here if the mapStatus is not the correct value (the user never used the detail disclosure), the map will just snap onto the current location 

    if mapStatus == "wentBack" { 
     print("Do not update location") 

     // assuming appropriate code is placed here but I am not sure what it is 


    } else { 
     print("Updated Current Location") 
    let center = CLLocationCoordinate2D(latitude: self.lastLocation.coordinate.latitude, longitude: self.lastLocation.coordinate.longitude) 
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)) 

    map.setRegion(region, animated: true) 

     locationManager.delegate = self 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest 
     if #available(iOS 8.0, *) { 
      locationManager.requestAlwaysAuthorization() 
     } else { 
      // Fallback on earlier versions 
     } 
     let noLocation = CLLocationCoordinate2D() 
     let viewRegion = MKCoordinateRegionMakeWithDistance(noLocation, 200, 200) 
     map.setRegion(viewRegion, animated: false) 

    } 
    } 

答えて

0

だから、のviewDidLoadが呼び出されているため、ユーザは詳細な開示に戻ってヒットしたときにマップが(持続しないことが判明prepareForSegueを使用して)。私はただのViewControllerを閉じ、そして唯一のviewDidAppearとないのviewDidLoadを呼び出すために

@IBAction func backButtonTapped(_ sender: UIBarButtonItem) { 
    self.dismiss(animated: true) 
    mapStatus = "wentBack" 

} 

を使用しました。

関連する問題