我想執行一個segue,它將一些變量傳遞給下一個視圖,包括從parse數據庫中檢索的一個變量currentID。在將currentID設置爲從數據庫下載的當前ID之後,不應調用performSegue。但是,當我運行代碼時,當它傳遞給下一個視圖時,currentID最終會變成一個空字符串。prepareForSegue before performSegue
這裏被稱爲我的代碼通過按鈕:
@IBAction func submitButtonPressed(_ sender: Any) {
let point = PFGeoPoint(latitude:0.0, longitude:0.0)
let testObject = PFObject(className: "Person")
testObject["inputAmount"] = inputAmount
testObject["outputAmount"] = outputAmount
testObject["inputCurrency"] = inputCurrency
testObject["outputCurrency"] = outputCurrency
testObject["location"] = point
testObject.saveInBackground { (success, error) -> Void in
// added test for success 11th July 2016
if success {
print("Object has been saved.")
self.currentID = String(describing: testObject.objectId!)
if(self.currentID != ""){
self.performSegue(withIdentifier: "mainToListSegue", sender: self)
}
} else {
if error != nil {
print (error)
} else {
print ("Error")
}
}
}
}
這裏是prepareForSegue方法:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let listViewController = (segue.destination as! UINavigationController).viewControllers[0] as! ListViewController
listViewController.inputCurrency = inputCurrency
listViewController.outputCurrency = outputCurrency
listViewController.inputAmount = inputAmount
listViewController.outputAmount = outputAmount
listViewController.currentID = currentID
listViewController.cellContent = cellContent
}
問題是什麼? –
你把你的segue連接到你的按鈕了嗎? – GIJOW
當傳遞給下一個視圖時,我如何獲得currentID不是空字符串? – cvrattos