【发布时间】:2015-02-08 04:21:06
【问题描述】:
我是 swift 语言的新手,知道这个问题是重复的。我发现了几个类似的问题和答案,但我无法找出问题所在。
我想将 detectionString 变量的值从 ScanViewController 传递给 ResultViewController。
ScanViewcontroller 如下:
import UIkit
class ScanViewController: UIViewController {
var detectionString : String!
override func viewDidLoad() {
super.viewDidLoad()
detectionString = “SomeDetectedString”
}
override func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject!) {
if (segue.identifier == "MySegue") {
var svc = segue.destinationViewController as ResultViewController;
svc.detectedString = detectionString
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
ResultViewController 如下:
import UIkit
class ResultViewController: UIViewController {
var detectedString: String!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor=UIColor.whiteColor()
println(detectedString)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
println(detectedString) 没有给我任何结果。问题是如何从 ScanViewController 中获取变量?
【问题讨论】: