カスタムMKMarkerAnnotationViewにUITableViewCellで表示したいテーブルビューがあります。このテーブルビューは専用のViewControllerに表示され、ViewControllerはTabBarControllerにあります。 2番目のタブはマップを表示します(ただし、ここでは重要ではありません)。UITableViewCellでカスタムMKMarkerAnnotationViewが初めて正しく表示されない
私はいくつかのラベルと実装では、クラス「EdgePinViewAnnotation」
とビューが含まれているテーブルビューに、私はのUITableViewCellを追加した、私のストーリーボードでMKMarkerAnnotationView から継承するクラス「EdgePinViewAnnotation」を作成しましたUITableViewCellのカスタム "EdgePinViewAnnotation"を初期化しています。 残念ながら、Cellがテーブルに表示されているときは、デフォルトのMKMarkerAnnotationViewが表示され、カスタマイズされた「EdgePinViewAnnotation」は表示されません。
TableViewをスクロールしてセルが画面外に出て、それをリフレッシュすると、「EdgePinViewAnnotation」が正しく表示されます。
なぜ初めて正しく表示されないのですか?ここで
私は私のカスタムMKMarkerAnnotationView
ここclass EdgePinViewAnnotation: MKMarkerAnnotationView {
override var annotation: MKAnnotation? {
willSet {
if let edgeAnnotation = newValue as? EdgePin {
animatesWhenAdded = true
isDraggable = true
canShowCallout = true
initRenderingProperties(pin: edgeAnnotation)
}
}
}
func initWith(edgePin:EdgePin) {
animatesWhenAdded = false
isDraggable = false
canShowCallout = false
initRenderingProperties(pin: edgePin)
}
func initRenderingProperties(pin edgePin:EdgePin) {
glyphTintColor = UIColor.white
glyphText = "\(edgePin.index)"
markerTintColor = edgePin.renderingColor
}
}
のための私のUITableViewからコード
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
if let cell = tableView.dequeueReusableCell(withIdentifier: CellId.DistanceConfigurationCellId, for: indexPath) as? DistanceConfigurationTableViewCell {
cell.theLabel.text = findMe.edgePoints[indexPath.row].address
let coord = findMe.edgePoints[indexPath.row].coordinate
cell.coordinates.text = "Lat:\(coord.latitude)/Long:\(coord.longitude)"
cell.theTextField.text = "\(findMe.edgePoints[indexPath.row].distance)"
cell.theTextField.delegate = self
cell.theTextField.tag = indexPath.row
cell.theMarker.initWith(edgePin:findMe.edgePoints[indexPath.row])
return cell
}
} else {
return UITableViewCell()
}
}
class DistanceConfigurationTableViewCell: UITableViewCell {
@IBOutlet weak var theLabel: UILabel!
@IBOutlet weak var coordinates: UILabel!
@IBOutlet weak var theTextField: UITextField!
@IBOutlet weak var theMarker: EdgePinViewAnnotation!
}