performSegueWithIdentifier错误

时间:2015-05-14 21:38:25

标签: ios swift segue

更新:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "addMapItem" {
        geocoder.geocodeAddressString(textAddress.text, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
            if let placemark = placemarks?[0] as? MKPlacemark {
                var lat = placemark.coordinate.latitude
                var long = placemark.coordinate.longitude
                var coordinates = placemark.coordinate
                var annotation = MKPointAnnotation()
                annotation.coordinate = placemark.coordinate
                annotation.title = self.textName.text
                annotation.subtitle = self.textAddress.text
                self.annotations.append(annotation)
                var destination : FirstViewController = segue.destinationViewController as! FirstViewController
                destination.savedItems = self.annotations
            }
        })
    }
}

在我的AddLocation视图控制器上,我有2个segues。按下按钮触发的按钮,输入数据并将其添加到表格中。另一个segue(我们正在处理的那个)获取数据,将地址转换为注释,然后将该注释传递给地图视图控制器上的变量并添加注释。

enter image description here

1 个答案:

答案 0 :(得分:1)

不使用UIButton.self作为发件人,而是使用sender。并且您不能使用performSegueWithIdentifier

的闭包
performSegueWithIdentifier("addMapItem", sender: UIButton.self) {
    // Some code
}

使用:

performSegueWithIdentifier("addMapItem", sender: sender)

我想你忘了在这一行添加self

destination.savedItems = annotations    // Should be self.annotations

这是应该放置代码的位置,以便在使用performSegueWithIdentifier时调用它:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "addMapItem" {
        // Your code
    }
}