我已将var message:String=""
设为global variable
,在函数中我计算其值,我必须通过ViewController
发送给另一个prepareForSegue
,但它结束了发送nil
值,知道如何通过segue发送最新值吗?谢谢全球变量:
var message2="bob"
准备segue方法:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "submitSegue") {
let svc = segue.destinationViewController as! Otpscreen;
svc.otpname = username.text!
svc.otppass = password.text!
svc.otp=message2
}
}
我正在计算值的其他方法:
func findMatch()->Void
{
print(username.text!+password.text!)
let authenticate=username.text!+password.text!
//line where i calculated hash
print(hash)
let num=strtoul(hash,nil,16)
print(num)
let finalhash=String(num)
let soap = SOAPEngine()
soap.responseHeader = true;
soap.setValue(username.text!, forKey: "userName")
soap.setValue(password.text!, forKey: "password")
soap.setValue(finalhash, forKey: "hashKey")
let dict:Dictionary = try! soap.syncRequestURL("someUrl", soapAction: "send method ") as Dictionary
NSLog("%@", dict);
let returnmessage=(dict["Body"]!["sendOTPResponse"]!!["sendOTPReturn"]!!["string"]!![1])
print(returnmessage)
message2=returnmessage as! String
}
答案 0 :(得分:0)
代码没有错,但问题是完成块,完成SOAPEngine响应后,segue方法必须在响应后调用。所以使用以下代码
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
<#code to be executed after a specified delay#>
//通过编程方式调用你的segue });