Penryn
Penryn

Reputation: 143

Unrecognised selector sent to instance by NSNotificationCenter

When i want to update a label via NSNotificationCenter is get an Runtime error but i don't know why. Slectors are named same.

ViewController2

@IBAction func saveSettings(sender: UIButton) {
    NSNotificationCenter.defaultCenter().postNotificationName("TimeRepairID", object: nil)
}

ViewController

    override func viewDidLoad() {
    super.viewDidLoad()
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "setTimeRepair", name: "TimeRepairID", object: nil)  
}

func setTimeRepair(notification: NSNotification){
    CurrentTimerepair.text = String(format:"%.1f", RepairTime.sharedInstance.TimeOfRepair())
    RFPTime.text = String(RepairTime.sharedInstance.ReadyForPickup())
}

so every time i press the save button in ViewController2 the app crashes with unrecognised selector sent to instance 0x13e63bd40 know any

Upvotes: 0

Views: 799

Answers (1)

Ruchish Shah
Ruchish Shah

Reputation: 319

You misses : after selector name as you are passing NSNotification as argument.

override func viewDidLoad() {
    super.viewDidLoad()
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "setTimeRepair:", name: "TimeRepairID", object: nil)
}

func setTimeRepair(notification: NSNotification){
    CurrentTimerepair.text = String(format:"%.1f", RepairTime.sharedInstance.TimeOfRepair())
    RFPTime.text = String(RepairTime.sharedInstance.ReadyForPickup())
}

Upvotes: 1

Related Questions