博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
swift之通知的使用
阅读量:4289 次
发布时间:2019-05-27

本文共 576 字,大约阅读时间需要 1 分钟。

*****注册通知、监听通知

NotificationCenter.default.addObserver(self, selector: #selector(noti(noti:)), name: NSNotification.Name(rawValue: "home"), object: nil)

注意:NSNotification.Name(rawValue: "home")是通知的名字home

@objc  func noti(noti:Notification){

    let dict:[String:String]=noti.userInfo as! [String : String]

    

    print("首页收到通知了\(dict["home"]!)")

    }

***************发送通知:

 NotificationCenter.default.post(name: NSNotification.Name(rawValue: "home"), object: nil, userInfo: ["home":"homestr"])

**************销毁通知

在析构函数中销毁通知的监听

deinit{

        NotificationCenter.default.removeObserver(self)//移除对通知的监听

    }

转载地址:http://mimgi.baihongyu.com/

你可能感兴趣的文章
自己编写的计算器
查看>>
视频物体检测
查看>>
Tomcat启动遇到的问题
查看>>
Gradle-gradlew
查看>>
grpc-整合gradle与代码生成
查看>>
grpc-gradle与grpc流程完美整合(3)
查看>>
设计模式-装饰模式(Decorator)
查看>>
git-子模块submodule
查看>>
设计模式-策略模式(Strategy)
查看>>
设计模式-观察者模式(Observer)
查看>>
java浅拷贝(shallow clone)与深拷贝(deep clone)
查看>>
Elasticsearch-terms搜索及结果优化
查看>>
Elasticsearch-对一个field进行多值全文本搜索
查看>>
Elasticsearch-best_fileds和most_fields策略分析以及cross-fields弊端的解决
查看>>
Elasticsearch-近似搜索
查看>>
Elasticsearch-前缀、通配符、正则、模糊搜索详解
查看>>
Elasticsearch-搜索推荐
查看>>
java-nio之Selector组件
查看>>
java-编码解密
查看>>
netty源码分析之-Future、ChannelFuture与ChannelPromise详解(3)
查看>>