1.贴上标签
cell?.dingdanCancel.tag = indexPath.row
2.viewDidLoad处定义通知
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(notices), name: NSNotification.Name(rawValue: "CancelNotification"), object: nil)
3.通知引发的事件
@objc func notices(notification: Notification) {
let userObj = notification.object as? Dictionary<String, Int>
let index = userObj!["tag"]
print("删除了:\(self.dingdanList[index!].hid)")
self.cancel(by: index!)
}
4.继发事件
//删除cell方法
@objc func cancel(by index: Int){
dingdanList.remove(at: index)
dingdanTableView.reloadData()
}
5.调用通知
@IBAction func cancel(_ sender: UIButton) {
let center = NotificationCenter.default
// center.post(name: NSNotification.Name(rawValue: "CancelNotification"), object: nil)
center.post(name: NSNotification.Name(rawValue: "CancelNotification"), object: ["tag": sender.tag])
}
网友评论