iOS быстрый просмотр карты в ячейке настраиваемого просмотра - PullRequest
0 голосов
/ 24 мая 2018

Код:

TreeScreenVC:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let entityHarvest = arrHarvest[indexPath.row]
            if entityHarvest.selfieDate != nil {
                var cell: TreePlantScreenCell3 = (tableView.dequeueReusableCell(withIdentifier: "cell1") as! TreePlantScreenCell3?)!
                    let loc = CLLocationCoordinate2DMake(entityHarvest.digLat , entityHarvest.digLong )
                    let span = MKCoordinateSpanMake(1.02,1.02)
                    let region =  MKCoordinateRegionMake(loc, span)
                    cell.mapView.setRegion(region, animated: true)

                    let lat = entityHarvest.digLat as Double
                    let long = entityHarvest.digLong as Double

                    let loc1 = CLLocation(latitude:lat, longitude:long)
                    cell.showLocation(location: loc1)

                    return cell
                }
}

CustomCell:

class TreePlantScreenCell3: UITableViewCell,MKMapViewDelegate {

 override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code

        mapView!.showsPointsOfInterest = true
        if let mapView = self.mapView {
            mapView.delegate = self
        }
    }

    //MARK: mapview delegate methods

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
        if (annotation is MKUserLocation) {
            return nil
        }

        let reuseId = "test"

        var anView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
        if anView == nil {

            anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
            anView?.frame.size = CGSize(width: 20.0, height: 21.0)
            anView?.image = UIImage(named:"landmark.png")
            anView?.canShowCallout = true
        } else {
            anView?.annotation = annotation
        }
        return anView
    }

    func showLocation(location:CLLocation) {
        let orgLocation = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)

        let dropPin = MKPointAnnotation()
        dropPin.coordinate = orgLocation

        mapView!.addAnnotation(dropPin)

self.mapView?.setRegion(MKCoordinateRegionMakeWithDistance(orgLocation, 500, 500), animated: true)
    }

}

Я создал пользовательскую ячейку в UITableView, имеющем MKMapView.Когда я загружаю вид карты, используя аннотации для каждой строки, тогда мой код работает нормально.Но проблема в том, что когда я прокручиваю табличное представление, представление карты загружается каждый раз, и прокрутка также не достаточно гладкая.Дайте мне знать, как я могу решить эту проблему.Я поделился кодом, помогите мне выяснить, что не так в моем коде.Любая помощь будет оценена.Заранее спасибо.

Ответы [ 2 ]

0 голосов
/ 24 мая 2018

Потому что вы выключаете свою клетку каждый раз, когда прокручиваете.Вместо этого вы можете сгенерировать ячейку карты только один раз и вернуть один и тот же объект в свой метод cellForRowAt. * ​​1001 *

0 голосов
/ 24 мая 2018

Вы можете использовать MKMapSnapshotter для плавной прокрутки табличного представления.

См. Также Swift 3 Добавить пользовательский пин-код аннотации к снимку MKMapSnapShotter .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...