Ios nib中的UISwitch值不会被更新

Ios nib中的UISwitch值不会被更新,ios,swift,Ios,Swift,我的开关位于nib的内部,nib位于tableview标题的内部。当我单击开关时,它只执行按钮开关.isOn,而不执行!按钮开关.isOn。它只给出按钮开关内部的值,似乎没有进入内部!按钮开关.isOn 谢谢 这是我的VC内的开关: extension PhoneNotificationViewController: PhoneNotificationHeaderViewDelegate { func pushNotificationSwitchTapped() { guard let

我的开关位于nib的内部,nib位于tableview标题的内部。当我单击开关时,它只执行
按钮开关.isOn
,而不执行
!按钮开关.isOn
。它只给出按钮开关内部的值,似乎没有进入
内部!按钮开关.isOn
谢谢

这是我的VC内的开关:

extension PhoneNotificationViewController: PhoneNotificationHeaderViewDelegate {
func pushNotificationSwitchTapped() {

    guard let phoneNotificationHeader = Bundle(for: type(of: self)).loadNibNamed("PhoneNotificationHeaderView", owner: self, options: nil)?.first as? PhoneNotificationHeaderView else {
        return
    }

    if phoneNotificationHeader.pushSwitch.isOn{
        //Disable Firebase from sending
        Globals.sharedInstance.pushStatus = true
        phoneNotificationHeader.pushSwitch.setOn(false, animated: true)
    }else{
        Globals.sharedInstance.pushStatus = false
        phoneNotificationHeader.pushSwitch.setOn(true, animated: true)
    }
    self.refreshUI()

}

没有“位于tableview标头内部的nib”这样的东西。每次通过说
loadNibNamed
加载nib时,都会得到它所包含视图的新副本。因此,每次调用
pushNotificationSwitchTapped
时,您都会从nib中获得一个全新的开关,并将其粘贴到界面中。那可能不是你想要的!当然,这个开关来自nib,只有一种状态,即您在nib编辑器中设置它的状态:它是开的

基于对nib是什么的误解,您需要完全放弃这种不正确的体系结构。您应该加载nib一次,从那时起,您应该通过与交换机本身交谈来引用交换机,即现在在您的界面中的交换机

extension PhoneNotificationViewController: PhoneNotificationHeaderViewDelegate {
func pushNotificationSwitchTapped() {

    guard let phoneNotificationHeader = Bundle(for: type(of: self)).loadNibNamed("PhoneNotificationHeaderView", owner: self, options: nil)?.first as? PhoneNotificationHeaderView else {
        return
    }

    if phoneNotificationHeader.pushSwitch.isOn{
        //Disable Firebase from sending
        Globals.sharedInstance.pushStatus = true
        phoneNotificationHeader.pushSwitch.setOn(false, animated: true)
    }else{
        Globals.sharedInstance.pushStatus = false
        phoneNotificationHeader.pushSwitch.setOn(true, animated: true)
    }
    self.refreshUI()

}