The following code causes a crash every time I save a task. The new data needs to be inputted to the Detail View controller and saved. This works, but the app terminates each time. Please tell me why this isn't working:
Code:
var detailViewController: DetailViewController? = nil
var managedObjectContext: NSManagedObjectContext? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem()
let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "addNewCourseWork")
self.navigationItem.rightBarButtonItem = addButton
if let split = self.splitViewController {
let controllers = split.viewControllers
self.detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? DetailViewController
}
//hide blank cells
let backgroundView = UIView(frame: CGRectZero)
tableView.tableFooterView = backgroundView
// register for receiving notification, I need to update detail view from this exact same class, not just any MasterView class instance...
NSNotificationCenter.defaultCenter().addObserver(self, selector:"MasterViewController.pushNewValuesToDetail", name: "updateDetailTableValues", object: nil)
}
func pushNewValuesToDetail() {
self.performSegueWithIdentifier("showDetail", sender: nil)
}
Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- MasterViewController.pushNewValuesToDetail]: unrecognized selector sent to instance 0x7fc622d1b820