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

Unable to show first viewcontroller passed values to second viewcontroller in swift

我的第二个 viewcontroller 包含 mkmapview.. 所有时间地图都必须仅在文本字段中显示当前位置地址值,但是当我从第一个 viewcontroller 发送值时,它应该首先显示 viewcontroller 的文本字段中的地址值

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

现在我将第一个 viewcontroller 地址发送给第二个 viewcontroller.. 但这里第二个 viewcontroller 总是只显示当前位置值.. 为什么?

第一个vc代码:发送地址到第2个vc:

 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 的初始值设定项,默认情况下 returns false,因此,您的代码在 if 语句中为您的文本字段启动值将永远不会得到 运行。这就是为什么您看不到从第一个 VC.

传递的值的原因