0

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
  • Possible duplicate of [unrecognized selector sent to instance](http://stackoverflow.com/questions/2455161/unrecognized-selector-sent-to-instance) – Michael May 13 '16 at 18:53
  • Feel free to mark your problem as solved if it has been resolved. – Putz1103 May 13 '16 at 20:34

1 Answers1

0

Try

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(pushNewValuesToDetail), name: "updateDetailTableValues", object: nil)

You don't need to note the base class, and the new method of creating a selector (in the latest version of Xcode) is #selector.

Putz1103
  • 6,211
  • 1
  • 18
  • 25