未设置自定义对象数组

时间:2016-07-23 14:38:23

标签: ios swift nsarray mapkit

我正在尝试将对象CustomPinAnnotation存储到数组中。我已经这样宣布:var pinArray = [CustomPinAnnotation]()

我在一个函数中调用Firebase,该函数获取了构建CustomPin的很多位置。

func loadStuff()
        _REF_BASE.child("Objects").observeSingleEventOfType(.Value, withBlock: { snapshot in
                    if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot]{
                        for snap in snapshots {
                            if let dict = snap.value as? Dictionary<String, AnyObject> {
                                let key = snap.key
                                let obj = objModel(lobbyKey: key, dictionary: pokeDict)
                                for location in obj.locations {
                                    let coord = location.locationCoordinate
                                    let customPin = CustomPinAnnotation()
                                    customPin.coordinate = coord.coordinate
                                    customPin.title = obj.name

                                    let time = NSDate(timeIntervalSince1970: location.time)
                                    let dayTimePeriodFormatter = NSDateFormatter()
                                    dayTimePeriodFormatter.dateFormat = "MMM dd YYYY hh:mm a"
                                    let dateString = dayTimePeriodFormatter.stringFromDate(time)
                                    customPin._detailedDescription = "Seen at " + dateString
                                    customPin.subtitle = "Seen at \(dateString)"
                                    customPin._pokemonName = obj.name
                                    customPin._imageName = obj.name
                                    customPin._successRate = location.successRate
                                    customPin._upVotes = location.upVotes
                                    customPin._downVotes = location.downVotes
                                    customPin._caughtAtTime = dateString
                                    self.pinToPass = customPin // send this custom pin with info
                                    self.pinArray.append(customPin)
    // self.mapView.addAnnotation(customPin);
                                }
                            }
                        }
                    }
                  }
                })

我的ViewDidLoad方法

self.PokeMapView.zoomEnabled = true

    loadStuff()
    self.mapView.addAnnotations(pinArray)
    self.mapView.showAnnotations(pinArray, animated: true)

注释行//self.MapView.addAnnotation(customPin)目前有效,但效率非常低,因为它会将地图上的对象固定在地图本身的当前范围内。但是,当我尝试添加如下所示的注释列表:MapView.addAnnotations(pinArray)时,没有任何作用,并且通过调试器,我告诉该数组包含0个元素。

如果有人可以帮助我,我将非常感激,因为我已经坚持了一段时间,这确实导致了糟糕的表现。

0 个答案:

没有答案