Skip to content

Instantly share code, notes, and snippets.

@trevorah
Last active February 11, 2016 11:27
Show Gist options
  • Save trevorah/0bb72a677f8afbc03753 to your computer and use it in GitHub Desktop.
Save trevorah/0bb72a677f8afbc03753 to your computer and use it in GitHub Desktop.
class MasterViewController: UITableViewController {
let cache = NSCache()
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let indexPath = tableView.indexPathForSelectedRow {
let object = objects[indexPath.row] as! NSDate
let controller = cache.objectForKey(object) as? DetailViewController ?? (storyboard?.instantiateViewControllerWithIdentifier("DetailViewController"))! as! DetailViewController
cache.setObject(controller, forKey: object)
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
navigationController!.popToRootViewControllerAnimated(false)
navigationController!.pushViewController(controller, animated: true)
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment