发出从API传递数据

时间:2016-01-12 22:50:52

标签: ios api serialization swift2

此代码来自位置tableView视图控制器,其中位置从四方API序列化,我抓取数据,将其传递回我创建事件的视图控制器。数据被正确序列化,填充tableView和所有数据,所以我现在不打算发布它,只是传递数据的segue方法。

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

    let indexPath = self.tableView.indexPathForSelectedRow

    let item = self.responseItems![indexPath!.row]

    var eventVC = CreateEventViewController()

    if segue.identifier == "pushBackToEventVC" {

        if let venue = item["venue"] as? NSDictionary {

            let locationString = venue["name"] as! String
            let location = venue["location"]

            //get lat/long strings

            print(location)

            eventVC.updateWithLocation(locationString)
            eventVC.updateWithGeoPoint(PFGeoPoint(latitude: locationLatitude, longitude: locationLongitude))

        }

        eventVC = segue.destinationViewController as! CreateEventViewController

        //pass location coordinates 
    }

//the rest of the segue method 

}

克里特事件视图控制器中的更新方法,当我在这些方法上设置断点时,我可以看到数据已正确传递,并且位置(PFGeoPoint)工作正常,但locationString(一个字符串)抛出“错误的指令错误“虽然它确实将其正确打印到控制台

func updateWithLocation(locationString: String) {

    print(locationString)
    self.locationLabel.text = locationString
}

func updateWithGeoPoint(venueLocation: PFGeoPoint) {

//        print(venueLocation)
    self.event?.location = venueLocation
    self.eventLocation = venueLocation
    print(self.eventLocation)
}

有什么想法吗?它基本上工作,但不会用字符串更新标签,虽然我可以看到它已正确传递。一如既往地感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

尝试使用此代码块,

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "pushBackToEventVC") {

        let detailViewController = ((segue.destinationViewController) as! CreateEventViewController)
        let indexPath = self.tableView!.indexPathForSelectedRow!

        detailViewController.locationString = venue["location"]
    }
}