私は、解析データベースから取得される変数currentIDを含む次のビューにいくつかの変数を渡すセグを実行しようとしています。 performSegueは、currentIDがデータベースからダウンロードされた現在のIDに設定されるまで呼び出すべきではありません。しかし、コードを実行すると、currentIDは次のビューに渡されるときに空の文字列になります。ここでbeforeForSegue 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
}
質問は何ですか? –
あなたのボタンにあなたのセグを接続しましたか? – GIJOW
次のビューに渡されるときに空の文字列ではないようにするにはどうすればよいですか? – cvrattos