Reputation: 338
Am trying to pass the text in the text field to another view
here is my code
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var next:itemDetailsView = segue.destinationViewController as! itemDetailsView
if(segue.identifier == "itemV"){
next.titleReceived == titleF.text
}
}
and here how i declared titleF
@IBOutlet weak var titleF: UITextField!
titleReceived in the next view
var titleReceived:String!
there is a button, when i click it, it should take me to the other view, but the app crashes when i put this line of code
next.titleReceived == titleF.text
Upvotes: 2
Views: 905
Reputation: 745
try like this:-
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "itemV") {
var next = segue.destinationViewController as itemDetailsView;
next.titleReceived = titleF.text
}
}
enjoy. its working here
Upvotes: 0
Reputation: 3205
You have write double Equuleus in next.titleReceived == titleF.text
instead of next.titleReceived = titleF.text
that's why second view
can't get value.
In second view
you are forcefully unwrapped the value which is nil
.
Upvotes: 3