ios - 传递自定义注解的数据
问题描述
如何传递Custom
注释的数据?我使用这个函数来执行segue:
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {}
class Custom: MKPointAnnotation {
var name: String?
var time: String?
var address: String?
}
解决方案
你可以试试
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
let anno = view.annotation as! Custom
print(anno.name)
// then access the properties of anno and use them for the segue
self.performSegue(withIdentifier:"SegueID",sender:anno)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SegueID" {
let des = segue.destination as! SecondVC
des.ann = sender as! Custom
}
}
class SecondVC:UIViewController {
@IBOutlet weak var lbl:UILabel!
var ann:Custom!
override func viewDidLoad() {
super.viewDidLoad()
self.lbl.text = ann.name
}
}
推荐阅读
- reactjs - React 中带有 useEffect 的异步上下文
- r - 在 R 中查看最佳 dtw 对齐
- python - 如何将输入转换为小写
- reporting-services - 在分组和行号方面需要帮助
- excel - 将文件保存到新驱动器后使用 Shell 运行批处理文件
- ios - 带有日期、小时、分钟和秒的 UIDatePicker
- jhipster - 在 Jhipster 应用程序中添加新的 bootswatch 主题
- angular - 使用 Angular 的 HttpClient 进行同步调用的最佳方式是什么?
- mysql - 如何获取mysql表中一行的分区名称
- visual-studio-code - 如何匹配文本伴侣语法中后跟冒号的字符串(或者如果更容易,则在前面)