I have a tableview set up in one view controller and I am trying to send the indexPath.row text to a new view controller's label. I am getting an error that says it found nil when unwrapping an optional value. If I print "selectedClass" in the viewController code shown below, I get the text of indexPath.row. If I print the text in the new viewController, I get nothing. Here is my code:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let classIndexPath = tableView.indexPathForSelectedRow!
let selectedCell = tableView.cellForRowAtIndexPath(classIndexPath)! as UITableViewCell
let spinningActivity = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
spinningActivity.labelText = "Just a Moment"
if reachabilityStatus == kNOTREACHABLE {
spinningActivity.hide(true)
self.displayAlert("No Internet Connection", message: "Please connect to the internet before continuing.")
} else {
spinningActivity.hide(true)
let selectedClass = selectedCell.textLabel!.text!
let newCardSetVC = self.storyboard?.instantiateViewControllerWithIdentifier("NewCardSetViewController") as! NewCardSetViewController
newCardSetVC.selectedClassLabel.text = selectedClass as String
self.performSegueWithIdentifier("addCardSetSegue", sender: self)
}
}
NewCardSetViewController
and using asegue
together. Is that really what you want? – Eendjeself.presentViewController(newCardSetVC, animated: true, completion: nil)
– boidkanperformSegueWithIdentifier
and then inprepareForSegue
do all the logic of passing the selectedClass value to the VC – boidkanNewCardSetVC
, and also use asegue
. That could be why your having this issue. Try using aprepareForSegue
method to pass along the text info you need – MikeG