从 API 传递数据问题

问题描述 投票:0回答:1

此代码来自位置

tableView
视图控制器,其中位置是从 Four Square 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)
}

有什么想法吗?它基本上可以工作,但不会用字符串更新标签,尽管我可以看到它已正确传递。

ios swift serialization swift2
1个回答
3
投票

尝试使用此代码块,

    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"]
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.