2016-05-13 116 views
0

下面的代码在每次保存任务时都会导致崩溃。新数据需要输入到Detail View控制器并保存。这可以工作,但应用程序每次都会终止。请告诉我这是为什么不工作:发送到实例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 
+0

[无法识别的选择器发送到实例]的可能重复(http://stackoverflow.com/questions/2455161/unrecognized-selector-sent-to-instance) – Michael

+0

随意标记您的问题解决,如果它已解决。 – Putz1103

回答

0

尝试

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

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

+0

完全正确!非常感谢! –

相关问题