无法在swift中显示第一个viewcontroller传递给第二个viewcontroller的值

无法在swift中显示第一个viewcontroller传递给第二个viewcontroller的值,swift,mkmapview,pushviewcontroller,Swift,Mkmapview,Pushviewcontroller,我的第二个viewcontroller包含mkmapview。。所有时间映射必须只在文本字段中显示当前位置地址值,但当我从firstviewcontroller发送值时,它只应在其文本字段中显示firstviewcontroller的地址值 最初,第二个viewcontroller文本字段显示当前位置值(如:城市、街道等) 现在我将第一个viewcontroller地址发送到第二个viewcontroller。。但此处secondviewcontroller始终仅显示当前位置值。。为什么? 第一

我的第二个viewcontroller包含mkmapview。。所有时间映射必须只在文本字段中显示当前位置地址值,但当我从firstviewcontroller发送值时,它只应在其文本字段中显示firstviewcontroller的地址值

最初,第二个viewcontroller文本字段显示当前位置值(如:城市、街道等)

现在我将第一个viewcontroller地址发送到第二个viewcontroller。。但此处secondviewcontroller始终仅显示当前位置值。。为什么?

第一个VC代码:将地址发送到第二个DVC:

 func btnEditTapped(cell: EditAddressTableViewCell) {
    if let indexPath = self.addeditTableview.indexPath(for: cell){
        print("edit button address index \(indexPath.row)")
          let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ProfileAddressViewController") as! ProfileAddressViewController
        
        var addrLo = addressArray[indexPath.row]

        print("in edit total mode address \(addrLo.pincode)")// in console in edit total mode address Optional("530013")
        viewController.editPincode = addrLo.pincode
        viewController.editStree = addrLo.streetName
        viewController.editColony = addrLo.city
        
    self.navigationController?.pushViewController(viewController, animated: true)
    }
}
我的第二个VC代码:这里我无法显示第一个VC的值为什么

class ProfileAddressViewController: UIViewController, CLLocationManagerDelegate, UISearchBarDelegate, DataEnteredDelegate {


var coordinate: CLLocationCoordinate2D = CLLocationCoordinate2D()
let locationManager = CLLocationManager()
   
var addressModel : ProfileModelUserAddress?
var editAddArray = [String]()

var addressArray = [String]()

@IBOutlet weak var titleNameLabel: UILabel!
@IBOutlet weak var backButton: UIButton!
@IBOutlet weak var pincodeField: UITextField!
@IBOutlet weak var cityField: UITextField!
@IBOutlet weak var streetField: UITextField!
@IBOutlet weak var mapView: MKMapView!

var editPincode: String?
var editStree: String?
var editColony: String?
var isEdit = Bool()


override func viewDidLoad() {
    super.viewDidLoad()
     self.locationManager.requestAlwaysAuthorization()
    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationManager.startUpdatingLocation()
    }
    if isEdit {
        titleNameLabel.text = "Edit Address"
        
        pincodeField.text = editPincode
        streetField.text = editStree
        colonyField.text = editColony
        
    }
}
   
@IBAction func backBtnClicked(_ sender: Any) {
    self.navigationController?.popViewController(animated: true)
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let _: CLLocationCoordinate2D = manager.location?.coordinate else { return }

    let userLocation :CLLocation = locations.last! as CLLocation
    latitude = userLocation.coordinate.latitude
    logitude = userLocation.coordinate.longitude
    let geocoder = CLGeocoder()
    geocoder.reverseGeocodeLocation(userLocation) { (placemarks, error) in
        if (error != nil){
            print("error in reverseGeocode")
        }
        let placemark = placemarks! as [CLPlacemark]

        if placemark.count>0{
            let placemark = placemarks![0]
            print(placemark.locality!)
            print(placemark.administrativeArea!)
            print(placemark.country!)
            let placemarkDictonary: NSDictionary=placemark.addressDictionary as! NSDictionary
            self.pincodeField.text=placemarkDictonary["ZIP"] as? String
            self.cityField.text=placemarkDictonary["City"] as? String
            self.streetField.text=placemarkDictonary["Street"] as? String
        }
    }

    let center = CLLocationCoordinate2D(latitude: latitude!, longitude: logitude!)

    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
    mapView.setRegion(region, animated: true)
    let myAnnotation: MKPointAnnotation = MKPointAnnotation()
    myAnnotation.coordinate = CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude);
    myAnnotation.title = "Current location"
    mapView.addAnnotation(myAnnotation)
}
}

请让我知道,如何在第二个vc中显示第一个vc的传递值

您是否在其他地方设置了
isEdit
的值?。如果不是,则
isEdit
的初始值将是
false
,因为您使用的是
Bool
的初始值设定项,默认情况下返回
false
,因此,为
If
语句中的文本字段初始化值的代码将永远不会运行。这就是为什么您看不到从第一个VC传递的值。

在第一个VC的viewController中添加此行。isEdit=true'@BijenderSinghShekhawat,如果我给出'viewController。isEdit=true“标题正在更改,但pincodeField、streetField、colonyField未更改…”。。。为什么我不知道。。。你应该一步一步地调试,看看到底发生了什么on@BijenderSinghShekhawat,谢谢你收到了,如果我给你
'viewController。isEdit=true'
标题正在更改,但pincodeField、streetField、colonyField未更改。。。为什么?