美文网首页
Swift Cell中观察者模式通知

Swift Cell中观察者模式通知

作者: 司南_01b7 | 来源:发表于2019-04-29 15:55 被阅读0次

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])

 }

相关文章

  • Swift Cell中观察者模式通知

    1.贴上标签 cell?.dingdanCancel.tag = indexPath.row 2.viewDidL...

  • iOS-通知中的知识点

    # 通知中的知识点 - **1.观察者模式:** - 观察者模式-发生时间后,以广播的形式,通知所有监听者 ---...

  • 采用观察者模式收集Android性能数据收集

    观察者模式观察者模式主要用来在一对多依赖关系中,通知被观察者同步状态或数据,android执行monkey期间收集...

  • java设计模式------观察者模式

    该模式业务逻辑写在观察者模式中的观察者内,当被观察者发生改变时,通知观察者进行更新。 类图: 一、自定义实现 1....

  • Python观察者模式

    观察者模式,被观察物自身属性通知观察者。

  • 设计模式之观察者模式

    观察者模式适合在一对多的关系,但被观察者状态或行为的改变需要通知观察者的情况。在平常开发中,观察者 模式是经常使用...

  • RXSwift笔记

    观察者模式:KVO、通知 被观察者:发出一个事件 观察者/订阅者:对被观察者对象进行响应 RXSwift:把程序中...

  • 关于NSNotification你可能不知道的东西

    NSNotification,又叫通知,属于设计模式中的观察者模式,在开发中很常见,相信大家都不陌生。关于NSNo...

  • Observer模式(观察者模式)

    观察者模式(Observer Pattern):当观察对象的状态变化时,会自动通知给观察者。观察者模式属于行为型模...

  • 观察者模式

    观察者模式 观察者模式的具体应用有两个:通知(notification)和KVO(Key-ValueObserve...

网友评论

      本文标题:Swift Cell中观察者模式通知

      本文链接:https://www.haomeiwen.com/subject/fbnynqtx.html