ios - 从 API 发出传递数据

标签 ios api serialization swift2

这段代码来自 locations tableView View Controller ,其中的位置是从 Four Square API 序列化的,我获取数据,将其传回我创建事件的 View Controller 。数据已正确序列化,填充了 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 

}

crete 事件 View Controller 中的更新方法,当我在这些方法上放置断点时,我可以看到数据已正确传递,位置(一个 PFGeoPoint)工作正常,但 locationString(一个字符串)抛出一个“Bad instruction error”,尽管它确实将其正确打印到控制台

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)
}

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

最佳答案

尝试改用此代码块,

    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"]
    }
}

关于ios - 从 API 发出传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34755276/

相关文章:

python - Django REST Framework - 教程 - 困惑

java - 包含 ArrayList 的反序列化对象具有所有空值

ios - 控制嵌套的 for 循环 Swift 3

ios - UIScrollView 或 UICollectionView - 使用缩放的相邻页面进行分页

php mysql 按日期排序(最近)

c# - Office 365 API 身份验证表单 REST API

android - 一个移动应用程序可以支持多个不同的 MDM 吗?

ios - 我可以在 NSURLSession 创建后更新其配置中的 cookie 吗?

facebook - 在本地主机上测试 Facebook 连接

java - Wicket - 持久化和非持久化 JPA 实体的序列化