【发布时间】:2018-03-22 10:40:29
【问题描述】:
我有一个包含 UISwitch 的 tableView 我正在使用 notificationCenter 来获取 UISwitch 的行。我现在如何使用该信息来关闭除我单击的开关之外的所有其他开关?
func creatNotification() {
let switchNotification = Notification.Name("answer")
NotificationCenter.default.addObserver(self,selector: #selector(getSwitchRow),name:switchNotification, object:nil)
}
@objc func getSwitchRow(notification: NSNotification){
rowNumber = notification.object as! Int
print("dataView2, getSwitchRow, rowNumber:", rowNumber)
}
@IBAction func `switch`(_ sender: UISwitch) {
var dataViewObject = DataView2()
dataViewObject.creatNotification()
let switchNotification = Notification.Name("answer")
NotificationCenter.default.post(name: switchNotification, object: rowNumber)
let switchNotification2 = Notification.Name("switch")
NotificationCenter.default.post(name: switchNotification, object: answerSwitch.isOn)
if(answerSwitch.isOn == true){
}
}
【问题讨论】:
-
你能分享你的代码吗?