Я новичок в быстром языке и знаю, что этот вопрос дублирован. Я нашел несколько похожих вопросов и ответов, но я не мог понять проблему.Передайте одну переменную с одного контроллера viewcontroller на другой viewcontroller
Я хочу передать значение переменной detectString в ResultViewController из ScanViewController.
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?
возможно дубликат [Проходят переменные из одного ViewController к другому в Swift] (http://stackoverflow.com/questions/24044108/pass-variables-from-one-viewcontroller-to-another-in-swift) – jtbandes