I'm new to swift and what I'm trying to figure out is how to make a detail view controller the segues from a table view. Right now I have the segue (with "showDetails" identifier) set up to open a the detail view controller. Here's the code I have in the table view controller that I want to segue from, just not sure if I'm doing this right. Any help would be appreciated!
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
//Core Data
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let managedContext : NSManagedObjectContext = appDelegate.managedObjectContext!
var fetchRequest = NSFetchRequest(entityName: "Log")
fetchRequest.returnsObjectsAsFaults = false;
var results: NSArray = managedContext.executeFetchRequest(fetchRequest, error: nil)!
var totalHoursWorkedSum: Double = 0
var logsArray = [String]()
for res in results {
var totalWorkTimeInHours = res.valueForKey("totalWorkTimeInHours") as Double
var dateString = res.valueForKey("dateString") as String
var comments = res.valueForKey("comments") as String
var loggedTotalWorkTimeInHours = "\(totalWorkTimeInHours)"
var loggedDateString = "\(dateString)"
var loggedComments = "\(comments)"
let destinationVC = segue.destinationViewController as LogDetailTableViewController
destinationVC.logTimeTextField.text = loggedTotalWorkTimeInHours
destinationVC.logDateTextField.text = loggedDateString
destinationVC.commentsTextField.text = loggedComments
}
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selectedLog: AnyObject = loggedTimes[indexPath.row]
let destinationVC = LogDetailTableViewController()
destinationVC.logTimeTextField = selectedLog as UITextField
destinationVC.logDateTextField = selectedLog as UITextField
destinationVC.commentsTextField = selectedLog as UITextField
destinationVC.performSegueWithIdentifier("showDetails", sender: self)
}
Not sure what to do differently I keep getting a nil crash when I try to tap on the tableview cell to try to show detail.