我无法 post 通知
I am unable to post the notifications
我搜索了 stack over flow 和所有站点,但无法 post 通知,我需要将数据从这个 class 传递到另一个 class 我需要发送 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()
}
}
这是另一个 class,我需要 post 要检查的 bool 值
@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)
}
}
您可以在发布通知时将数据发送到对象中
let data : NSDictionary = ["DataKey" : "DataValue"]
NotificationCenter.default.post(name: NSNotification.Name(rawValue:
"notification"), object: data)
并且在发布之后,您可以在通知处理程序中获取相同的数据。
我搜索了 stack over flow 和所有站点,但无法 post 通知,我需要将数据从这个 class 传递到另一个 class 我需要发送 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()
}
}
这是另一个 class,我需要 post 要检查的 bool 值
@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)
}
}
您可以在发布通知时将数据发送到对象中
let data : NSDictionary = ["DataKey" : "DataValue"]
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "notification"), object: data)
并且在发布之后,您可以在通知处理程序中获取相同的数据。