gpt4 book ai didi

ios - NSNotificationCenter 发送到实例的无法识别的选择器

转载 作者:行者123 更新时间:2023-11-29 01:48:36 24 4
gpt4 key购买 nike

当我想通过 NSNotificationCenter 更新标签时出现运行时错误,但我不知道为什么。选择器的名称相同。

ViewController2

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

View Controller

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

所以每次我在 ViewController2 中按下保存按钮时,应用程序崩溃,无法识别的选择器发送到实例 0x13e63bd40 知道任何

最佳答案

当您将 NSNotification 作为参数传递时,您在选择器名称之后错过了 :

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

关于ios - NSNotificationCenter 发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31658510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com