I am struggling to pass a selected option in a picker view in one view controller to the label text of a label in another view controller. The VC with the label I want to update has the Storyboard Identifier: "PageContentViewController". The VC with my picker (periodPicker) has a 'Select' button at the bottom of the view that calls the following function when pressed:
@IBAction func selectButtonPressed(_ sender: Any) {
let row = periodPicker.selectedRow(inComponent: 0)
let selected = periodType[row]
let pageContentViewController = self.storyboard?.instantiateViewController(withIdentifier: "PageContentViewController") as! PageContentViewController
pageContentViewController.periodLabelTitle = selected
}
The code for the PageContentViewController
class is
import UIKit
class PageContentViewController: UIViewController {
@IBOutlet weak var periodLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
var pageIndex: Int = 0
var periodLabelTitle: String!
var dateLabelTitle: String!
override func viewDidLoad() {
super.viewDidLoad()
periodLabel.text = periodLabelTitle
dateLabel.text = dateLabelTitle
}
}
When navigating to PageContentViewController
via the tab buttons (it is a tab-based application), the label text does not update. Where am I going wrong?
I have tried employing the periodLabel.text = periodLabelTitle
command in a viewDidAppear
method for pageContentViewController
but this still didn't work (after the 'Select' button was pressed previously).
I believe it is also relevant to mention that PageContentViewController
is a child VC of a UIPageViewController
.