模拟器(iOS)中的结果不一致?

时间:2016-04-26 21:08:42

标签: ios xcode swift

我正在建立一个基本的地理围栏应用程序,允许用户创建地理围栏,在MKMapView上查看它们,以及激活和停用它们。它基于Ray Wenderlich教程,但我已经通过多种方式对其进行了调整。也就是说,我使用Realm来保存数据,我创建了一个单独的LocationHandler类,它充当LocationManagerDelegate并拥有一个LocationManager。通常,我试图将一些函数从viewControllers中移出并移到单独的类中。

一切似乎都有效,除了定期地映射注释和叠加在模拟器中没有正确呈现。大约20%的时间注释和叠加不会被删除。或者,颜色不会发生变化。或者,圆形叠加将改变颜色,但相关的引脚不会。

这是由于我的代码中出现了一些错误,还是这是使用模拟器的工件? 谢谢你的帮助

编辑以添加一些代码: 在视图控制器中

//Clicking the 'x' deletes the geofence
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView,     calloutAccessoryControlTapped control: UIControl) {

        let anAnnotation = view.annotation as! GeofenceAnnotation
        let geofence = anAnnotation.geofence

        //stop monitoring geofence
        locationManager.stopMonitoringGeofence(geofence!)

        //remove representation of geofence from map
        removeGeofenceRadiusCircle((geofence?.identifier)!)
        mapView.removeAnnotation(anAnnotation)


        //delete geofence from realm
        try! realm.write {
            realm.delete(geofence!)
        }
        updateGeofenceCount()
    }
//Go through all overlays and remove appropriate one
    func removeGeofenceRadiusCircle(id: String) {
        self.mapView.delegate = self
        if let overlays = mapView?.overlays {
            for ol in overlays {
                if let circleOverlay = ol as? GeofenceRadiusCircle {
                    let aId = circleOverlay.id
                    if aId == id {
                        mapView?.removeOverlay(circleOverlay)
                        break
                    }
                }
            }
        }
    }

MKAnnotation的子类     class GeofenceAnnotation:NSObject,MKAnnotation {

    var coordinate: CLLocationCoordinate2D
    var title: String?
    var subtitle: String?
    var geofence: Geofence?

    init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String,   geofence: Geofence? = nil) {
        self.coordinate = coordinate
        self.title = title
        self.subtitle = subtitle
        self.geofence = geofence
    }

MKCircle的子类

class GeofenceRadiusCircle: MKCircle{
    var geofence: Geofence?
    var color: UIColor?
    var id: String = ""
}

1 个答案:

答案 0 :(得分:0)

这似乎是我身边的一点点错误,也可能是模拟器的错误。在重新绘制viewWillAppear到帐户之前,我需要删除旧的叠加层。这似乎解决了叠加和注释问题。我也遇到了一个问题,用户位置没有在mapView中显示所有时间,而且当我在手机上运行应用程序时似乎不是这样。