私はスレッドを読んでいた:IBOutlet of another view controller is nilアクセス
私はそれに非常に似た問題を抱えています。
RequestViewController
class DenunciasResueltasViewController: UIViewController {
@IBOutlet var mapView: GMSMapView!
var solicitudes = [SolicitudesModel]()
var tempMap: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: 3.4824182, longitude: -8.1776567, zoom: 15)
self.mapView.camera = camera
}
func recenterMap(latitude:Float!, longitude:Float!) -> Void {
let coordinates = CLLocationCoordinate2DMake(CLLocationDegrees(latitude), CLLocationDegrees(longitude))
mapView = tempMap
self.mapView.animate(toLocation: coordinates)
}
RequestTableViewController
class RequestTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//Some code to fill the table
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "RequestVC") as! RequestViewController
viewController.recenterMap(latitude: solicitudes[indexPath.row].getLatitude(), longitude: solicitudes[indexPath.row].getLongitude())
return cell
}
}
両方のコンポーネントは、実行時に同時に初期化され、私は意味、両方が同じビューの一部です。
そしてユーザーが、私はそのresasonためmapView
を更新したい「行」をクリックしたときに、私はこの方法を使用している「RecenterMap」
しかし、変数「self.mapView」は常に '無し'。 この値はどのように更新できますか?
CLCoordinateプロパティを設定すると、マップをどこに配置するか、viewcontrollerを作成するときに設定したり、viewDidLoafで表示されたり表示されたりすると、その値に対して 'recenterMap()'が呼び出されます。 – Larme