目前在我的应用程序上工作,学习swift(我是全新的)。我遇到了一个我似乎无法解决的错误。 我的故事板中有两个视图,有两个viewcontrollers,因此ViewController&设置。
在"设置"查看我有一个textfield
,并在" ViewController"查看我有一个标签。
我想在文本字段中传递"设置"到我的标签" viewcontroller"
目前我收到以下错误:
类型的值' UIViewController'没有会员' ViewController'
对于输入字段,我的代码看起来有点像这样:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var secondVC: ViewController = segue.destination.ViewController as ViewController
secondVC.receivedString = textField.text!
}
标签:
class ViewController: UIViewController {
@IBOutlet var city: UILabel!
var receivedString: String = ""
override func viewDidLoad() {
super.viewDidLoad()
label.text = receivedString
}
" label.text"给我一个未解决的标识符..
答案 0 :(得分:1)
要在Swift 3中获取目标viewController
,它只是segue.destination
而不是segue.destination.ViewController
。
var secondVC = segue.destination as! ViewController
对于第二个错误,您声明了名为UILabel
而非city
的{{1}},因此必须为label