无法识别的选择器发送到实例Swift 2.1



每次保存任务时,以下代码都会导致崩溃。新数据需要输入到局部视图控制器并保存。这是有效的,但应用程序每次都会终止。请告诉我为什么这不起作用:

代码:

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)
}

错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- MasterViewController.pushNewValuesToDetail]: unrecognized selector sent to instance 0x7fc622d1b820

尝试

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

您不需要注意基类,创建选择器的新方法(在最新版本的Xcode中)是#selector

最新更新