Hi
I am stuck on using segue to pass data from one view controller to another.
Here is the code I am trying to use.
// MARK: - Actions & Segues
@IBAction func SelectDevice(sender: AnyObject) {
performSegueWithIdentifier("deviceSelect", sender: sender)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "deviceSelect" {
let loc = segue.destinationViewController as? calculationViewController
loc!.makerTextField = dmakerTextField
loc!.modelTextField = dmodelTextField
loc!.panelWidthTextField = dpanelwidthTextField
loc!.panelHightTextField = dpanelhightTextField
loc!.panelPitchTextField = dpanelpitchTextField
tableView.reloadData()
}
}
In the calculationViewController I have coresponding textfield
Hope someone could help me with some advice.
`prepareForSegue’ gets called after the destination view controller has been instantiated, but before it’s loaded (i.e. before it calls its own ‘viewDidLoad’ function). So, your calculationViewController might have instantiated its table view, its text fields, etc., but the views won’t have been laid out, the table view won’t have loaded any data (and so won’t be able to reload it, either), etc…
Furthermore, it looks like you’re trying to pass the actual text field controls from this view controller to the next one (I assume the properties ending in ‘TextField’ are all UITextFields?). This seems unlikely to be a good plan - it means that your calculationViewController will expect to read inputs from this view controller’s text fields, but not any text fields you display on the calculationViewController.
Generally, each view controller should control its own views and controls, and shouldn’t have any knowledge of the views & controls which make up other view controllers. What you should be passing between view controllers is the data which needs displaying (e.g. the text values from the text fields, maybe), and then use the destination view controller’s ‘viewDidLoad’ to display that data in its own views/controls.