I'm learning swift 2. I'm trying to pass the data of the cell (UITableView) that is tapped to the new View Controller. But I constantly get the error of: "unexpectedly found nil while unwrapping an Optional value
" for the code line "destination!.label.text = valueToPass
".
Below is my code.
May I know what should I do to solve it? I have spent hours but still stuck with it.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indexPath = tableView.indexPathForSelectedRow;
let Mycell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;
valueToPass = (Mycell.textLabel?.text)!
performSegueWithIdentifier("webNext", sender: self)
print("\(indexPath!.row)")
print(valueToPass)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "webNext") {
let destination = segue.destinationViewController as? web___ViewController
destination!.label.text = valueToPass
}
}