【问题标题】:How do I pass a value from my SplitView controller to a map?如何将值从我的 SplitView 控制器传递到地图?
【发布时间】:2015-08-21 06:58:56
【问题描述】:

所以我有一个 SplitView 控制器,当我选择一个我知道如何使用 segue 转到详细视图的单元格时,单元格有城市和州(例如:达拉斯、德克萨斯等)。但是,如何向另一个包含地图的 UIViewController 发送数据?

创建 segue 后,与 SplitView 关联的代码如下所示:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        let cell:UITableViewCell = sender as! UITableViewCell

        let destinationViewController:ViewController = segue.destinationViewController as! ViewController
              // “cell.textLable” is where the value is passed from the SplitView
if let text = cell.textLabel!.text {

            let incedent = LocationIncedent(sName: text)
            destinationViewController.detailString = "Lat:" + String(stringInterpolationSegment: incedent.incLat) + " Long:" + String(stringInterpolationSegment: incedent.incLong)

DestinationViewController 是标签接受显示值的地方。但是,如何将值发送到地图而不是标签。此外,我需要将纬度和经度坐标传递给 CLLocationCoordinate2D 方法。

谢谢

【问题讨论】:

    标签: swift storyboard


    【解决方案1】:

    您在 destinationViewController 上为要传递的每个对象创建一个属性,并在 segue 方法中分配此属性。

    在您的destinationViewController 的viewDidLoad() 中,您可以使用签署到这些属性的数据来​​填充MKMapView...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多