委托:MKMapView是零,虽然它已初始化

时间:2016-01-05 12:32:09

标签: ios swift dictionary bluetooth delegates

当我从设备收到我的蓝牙类(新)值时,我会给代表打电话。所以蓝牙类正在后台运行。

我的协议很简单:

protocol RefreshPositionInDrive {
func changingValue(latitude: Double, longitude: Double)
}

在我的UIViewController中,我初始化一个地图。当我在没有代表的情况下开始工作时,这段代码工作正常。

func initializeMapResolution() {
    let regionRadius: CLLocationDistance = 1000
    let initialLocation = CLLocation(latitude: 50.910349, longitude: 8.066895)
    let coordinateRegion = MKCoordinateRegionMakeWithDistance(initialLocation.coordinate,
    regionRadius * 1.5, regionRadius * 1.5)
    MapDrive.setRegion(coordinateRegion, animated: true)
    MapDrive.delegate = self
}

我的协议中的方法:

func changingValue(latitude: Double,longitude: Double) {
    print("THE NEW COORDINATES \(latitude)  \(longitude)")

    if self.MapDrive == nil {
       print("Is nil")
    } else {
        updateTheMap()
    }
}

输出:

  

THE NEW COORDINATES 25.012x 16.992

     

但我不明白。我首先初始化我的地图。之后调用changingValue。 MapDrive怎么可能没有? 我在没有委托的情况下测试了代码,只是在我的UIViewController中使用了一些修复坐标,并且出现了注释。

(我第一次与代表一起工作。)

修改

我模糊不清:我的MapDrive:

 @IBOutlet weak var MapDrive: MKMapView!

所以我不能像你的意思那样实例化?

1 个答案:

答案 0 :(得分:1)

您想要将一个MapDrive实例引用到UIViewController,当您的函数结束时,您的MapDrive可能会被释放。

2015-12-31 2015-11-30 2015-10-31
31/12/16 30/11/15 31/10/15