Reputation:
Currently working on my app, to learn swift (Im completely new). And I came across an error that I just cant seem to resolve. I have two views in my storyboard with two viewcontrollers hence ViewController & Settings.
On the "Settings" view I have a textfield
, and on the "ViewController" view i have a label.
I want to pass text from the textfield on "settings" to my label on "viewcontroller"
Currently i get the following error:
value of type 'UIViewController' has no member 'ViewController'
My code looks somewhat like this for the input field:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var secondVC: ViewController = segue.destination.ViewController as ViewController
secondVC.receivedString = textField.text!
}
for the label:
class ViewController: UIViewController {
@IBOutlet var city: UILabel!
var receivedString: String = ""
override func viewDidLoad() {
super.viewDidLoad()
label.text = receivedString
}
the "label.text" gives me an unresolved identifier too..
Upvotes: 0
Views: 1874
Reputation: 72410
To get the destination viewController
in Swift 3 it is just segue.destination
not segue.destination.ViewController
.
var secondVC = segue.destination as! ViewController
For second error you have declare UILabel
with name city
not label
so it must be city.text = receivedString
Upvotes: 1