I have everything working when transitioning from my tableview to my view controller. The only issue I have is when I go from tableview to viewcontrller my variable is not passed. It shows up as blank.
When I print to console in the tableview controller I see that my variable is not blank but when receiving it in the viewcontroller it is blank. I cannot figure out why my variable is not passing to my viewcontroller. Any help or ideas are appreciated.
Tableview Controller method:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow!
let currentCell = tableView.cellForRow(at: indexPath)! as UITableViewCell
//valueToPass = currentCell.textLabel?.text
let myVC = storyboard?.instantiateViewController(withIdentifier: "selectedMeterView") as! SelectMeterDetailsViewController
myVC.stringPassed = (currentCell.textLabel?.text)!
print(myVC.stringPassed)
navigationController?.pushViewController(myVC, animated: true)
}
This my viewcontroller to receive the variable:
import UIKit
import Foundation
class SelectMeterDetailsViewController: UIViewController {
var stringPassed = ""
@IBOutlet weak var meterNameOuput: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
meterNameOuput.text = "THis is a test \(stringPassed)"
}
@IBAction func goBackToTableview(_ sender: UIBarButtonItem) {
performSegue(withIdentifier: "backToTableVIew", sender: self)
}
}