I'm trying to create my first iOS app
I got this error "unexpectedly found nil while unwrapping an Optional value" when I try to access variable from my delegate view controller
I'm trying to get a pressed cell value to be set as label text on my target controller
This is the first controller
class SearchStationViewController: UITableViewController, writeValueBackDelegate {
var selectedStation: String!
var fromStationValue: String! = "None"
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedStation = stations[indexPath.row].StationName
fromStationValue = selectedStation
let vc = SelectedStationViewController()
vc.fromStationValue = self.fromStationValue
vc.delegate = self
self.dismissViewControllerAnimated(true, completion: nil)
}
}
And the target controller which I would like it's label.text to be changed
protocol writeValueBackDelegate {
var fromStationValue: String! {get set}
}
class SelectedStationViewController: UITableViewController {
@IBOutlet weak var stationFrom: UILabel!
var delegate: writeValueBackDelegate! = nil
var fromStationValue: String! = "None"
override func viewDidLoad() {
super.viewDidLoad()
stationFrom.text = fromStationValue
}
}