Well, I'm stuck. I was having a tricky problem with getting my custom table view cell to segue to the 'details' portion of my Master-Detail application, and this other StackOverflow post fixed it, calling the prepareForSegue function. I still wasn't getting the results I was expecting, and I found a big problem: passing the cell's attributes to the detail section requires a cell to be selected, and the code from that post deselects the cell immediately before the segue. Seems like an easy fix, but when I removed that line the program crashed when I clicked on a cell. I don't really know what to do here (100% of my iOS experience is from the last 48 hours), and am hoping someone here can help.
Code Involved:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let object = objects[indexPath.row]
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: false) // What appears to be the problem
performSegueWithIdentifier("showDetail", sender: cell)
}
Error (When I remove the deselect line):
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
(In the editor this pops up: THREAD 1: EXC_BREAKPOINT)
All help is appreciated.