Reputation: 4376
I'm working on an app that consists of forms, the structure of which goes as follows:
The idea, basically, is a table, within a table. Each table has an identifier, the "parent". MainTable's parent is MainForm, and SubTable's parent is MainTable.
We pass this between the forms via prepareForSegue
:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "CorrosionAddERMeasurementSegue" {
let vc : CorrosionAddERMeasurementFormViewController = segue.destinationViewController as! CorrosionAddERMeasurementFormViewController
vc.selectedCorrosionRateID = self.selectedCorrosionRateID
}
}
For the first part, it works fine. I can pass MainForm's ID to MainTable Form, ensuring that no matter what MainTable's actual ID is, it will always belong to MainForm.
Here's where things get dicey:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "AddCorrosionSampleTreatmentSegue" {
let vc : CorrosionAddSampleTreatmentFormViewController = segue.destinationViewController as! CorrosionAddSampleTreatmentFormViewController
vc.selectedCorrosionErMeasurementID = self.selectedCorrosionErMeasurementID
}
}
When the next xib loads, I immediately print the value of selectedCorrosionErMeasurementID
which returns nil
.
This is the code for switching to the next form:
func addSampleButtonPressed() {
print("Add Button Pressed. Selected Corrosion Measurements: \(self.selectedCorrosionErMeasurementID)")
self.performSegueWithIdentifier("CorrosionAddSampleTreatmentSegue", sender: self)
}
And that does print out the correct parent ID value. Here's the opening statements of the SubTable Form:
class CorrosionAddSampleTreatmentFormViewController: BaseViewController, SampleTreatmentFormViewDelegate, UIPickerViewDataSource,UIPickerViewDelegate,UICollectionViewDataSource, UICollectionViewDelegate {
var corrosionAddSampleFormView : SurfaceThermalSamplingAddSamplingView!
var selectedCorrosionErMeasurementID : String!
override func viewDidLoad() {
print("Selected ID from FormCorrosionER is: \(self.selectedCorrosionErMeasurementID)")
super.viewDidLoad()
}
}
Nothing to suggest that the value is being erased.
Is there anything I need to check? Perhaps there's a limit to how deep I can go into segues? Any suggestions?
Upvotes: 0
Views: 29
Reputation: 7746
Assuming I understood correctly, I believe your segue identifiers are mis-matched
self.performSegueWithIdentifier("CorrosionAddSampleTreatmentSegue", sender: self)
vs
if segue.identifier == "AddCorrosionSampleTreatmentSegue" {
If the first line is supposed to lead to the second, the identifiers need to be identical.
Upvotes: 1