2017-09-05 48 views
0

我已经搜索了堆栈上的流和所有网站,但无法发布通知,我需要将数据从这个类传递给另一个类我需要发送bool值来验证任何人都可以帮助我如何传递布尔值?我无法发布通知

这里是它的代码

 radioSelected = false 
     NotificationCenter.default.addObserver(self, selector: #selector(paymentRadioEnable(n:)), name: NSNotification.Name.init(rawValue: "notification"), object: nil) 
     self.shippingmethodURL() 
     shippingTableView.delegate = self 
     shippingTableView.dataSource = self 
     shippingTableView.rowHeight = UITableViewAutomaticDimension 
     shippingTableView.estimatedRowHeight = shippingTableView.rowHeight 
     // Initialization code 
    } 
    func paymentRadioEnable(n:NSNotification){ 

    } 
    func paymentRadioAction(button : KGRadioButton) { 
     _ = button.center 
     let centralPoint = button.superview?.convert(button.center, to:self.shippingTableView) 
     let indexPath = self.shippingTableView.indexPathForRow(at: centralPoint!) 
     if button.isSelected { 

     } else{ 
      chekIndex = indexPath 
      radioSelected = true 
      self.shippingTableView.reloadData() 
     } 
    } 

这是另一个类,我需要发布布尔值来检查

@IBAction func continueButtonAction(_ sender: Any) { 
     NotificationCenter.default.post(name: NSNotification.Name(rawValue: "notification"), object: nil) 
      if radioSelected == false { 
       let radiobutton = SCLAlertView() 
       _ = radiobutton.showError("Warning", subTitle: "Please select shipping method", closeButtonTitle: "OK") 
      }else{ 
       let storyboard = UIStoryboard(name: "Main", bundle: nil) 
       let addtoCartVC = storyboard.instantiateViewController(withIdentifier: "payment") as! PaymentMethodViewController 
       self.navigationController?.pushViewController(addtoCartVC, animated: true) 
      } 
    } 
+0

观察员班是否已初始化? –

+0

如何知道观察者初始化? @BalajiKondalrayal –

回答

1

您可以在时间中的数据发送到对象发布通知

let data:NSDictionary = [“DataKey”:“DataValue”]

NotificationCenter.default.post(名称:NSNotification.Name(rawValue: “通知”),对象:数据)

和张贴后,你可以在通知处理相同的数据。

+0

我需要发送真或假只是不像NSDictionary fomat @Ajay Kokcha –

+0

我倾向于解释NSNotification API如下:'object'通知的发件人(在这种情况下,'self'),'userInfo'是你打算传递的详细信息(在这种情况下是'data')。 **然而**,大部分时间发件人并不重要,上面的用法是一个明智的捷径。 –

+0

@VamsiKrishnaS在这种情况下,你可以传递布尔值作为'object'参数。文档说它的参数是Swift类型的'Any?',所以它应该接受一个布尔常量。 –

相关问题