Ios MapView委托返回nil
我正在做一个应用程序,我在一个ViewController中输入一个地址,这个地址转到另一个ViewController中的MapView并添加注释。 但当我在返回mapview时添加地址时,应用程序崩溃,并显示我的mapview.delegate为零。 以下是我的地址输入代码:Ios MapView委托返回nil,ios,swift,mkmapviewdelegate,Ios,Swift,Mkmapviewdelegate,我正在做一个应用程序,我在一个ViewController中输入一个地址,这个地址转到另一个ViewController中的MapView并添加注释。 但当我在返回mapview时添加地址时,应用程序崩溃,并显示我的mapview.delegate为零。 以下是我的地址输入代码: @IBAction func createButtonPressed(_sender: Any) { guard let address = addresTxtFd.text else {
@IBAction func createButtonPressed(_sender: Any) {
guard let address = addresTxtFd.text else { return }
guard let date = dateTxtFd.text else { return }
let geocoder = CLGeocoder()
geocoder.geocodeAddressString((address)) { (placemarks, error) in
if error == nil {
if let placemark = placemarks?[0] {
let location = placemark.location!
let latitude = location.coordinate.latitude
let longitude = location.coordinate.longitude
self.locatinService.setLocation(address: address, date: date, latidude: latitude, longitude: longitude, completion: { (success) in
if success {
let map = MapVC()
map.modalPresentationStyle = .custom
self.present(map, animated: true, completion: nil)
// LocationServices().dropPin()
}
})
}
}
}
这是我的地图视图:
class MapVC: UIViewController {
// Outlets
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var newGSButton: UIButton!
// Variables
var locationManager = CLLocationManager()
var locationAuthorization = CLLocationManager.authorizationStatus()
var regionRadius: Double = 1000
let annotations = MKPointAnnotation()
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
locationManager.delegate = self
configureCurrentLocation()
}
@IBAction func centerUserLocation(_ sender: Any) {
centerUserCurrentLocation()
}
@IBAction func newGSButtonPressed(_ sender: Any) {
if AuthService.instance.isLoggedIn
{
let newGs = NewGarageSaleVC()
newGs.modalPresentationStyle = .custom
present(newGs, animated: true, completion: nil)
} else {
performSegue(withIdentifier: TO_LOGIN, sender: nil)
}
}
}
下面是错误:
线程1:致命错误:在展开文件时意外发现nil
可选值
谢谢大家。uhh。。它没有试图打开代理。。此外,您“可能”有未定义的行为
geocodeAddressString
在后台线程上运行。。不是主线。检查您的插座是否已设置。在行mapView.delegate
上添加断点,然后键入po mapView==nil
,查看是否已设置断点。如果没有看到整个错误消息本身,我们无法为您找出错误消息。嗨,布兰登,谢谢您的回复。我添加了断点。当应用程序第一次加载mapView时,mapView有一个值。当我从其他视图控制器返回时,mapView为零。Idk,如果我需要重新加载mapview或类似的东西。