- NSNotification 通知
行业碧油鸡
+++Categories=["iOS",]Tags=["iOS","NSNotification",]date="2014-07-03T18:56:41+08:00"title="NSNotification通知"+++NSNotification一个对象通知另外一个对象,可以用来传递参数、通信等作用,与delegate的一对一不同,通知是一对多的。在一个对象中注册了通知,那么其他任意对象都可以
- Objective-C 通知(NSNotification)
FlyElephant
Objective-C的通知是负责对象之间的通信,可以在NSNotificationCenter中注册观察对象,对象也可以NSNotificationCenter发送消息通知.发送对象和接收对象是一对多的关系,通知算是多播(multiCast)形式的一种,如果是向非特定的多个对象发送消息称之为广播(broadcast).同步or异步通知的注册和发送都是在NSNotificationCenter中实
- KVC、KVO、NSNotification、delegate优缺点总结
小呀小苹果呀
KVC、KVO、NSNotification、delegate的基本概念和使用方法这里不再赘述,下文主要总结一下四者的优缺点。一.KVC优点(1)可以直接通过字符串的名字(Key)来访问类属性或成员变量,而不是通过调用Setter方法、Getter方法进行访问;(2)可以通过keyPath嵌套访问缺点(1)如果key只写错,编写的时候不会报错,但是运行的时候会报错二.KVO优点(1)能够提供一种简
- swift NotificationCenter 通知的简单用法
MrLSX
通知的作用是一对多,跨界面实现调用函数,依据的是KVO//1.注册通知NotificationCenter.default.addObserver(self,selector:#selector(ceshi),name:NSNotification.Name(rawValue:"aaa"),object:nil)@objcfuncceshi(){collectionView.backgroundC
- 323,IOS中观察者模式的定义
枫叶1234
观察者模式(ObserverPattern):定义对象间的一种一对多依赖关系,使得每当一个对象状态发生改变时,其相关依赖对象皆得到通知并被自动更新。在iOS中典型的观察者模式实现方式为NSNotificationCenter和KVO。一、NSNotificationCenterimage.png在CocoaTouch框架中NSNotificationCenter和NSNotification对象实
- 478,NSNotificationQueue(通知队列)(NSNotificationQueue是notification Center的缓冲池,如果我们使用普通的- (void)postNo...
枫叶1234
NSNotificationQueue是notificationCenter的缓冲池。如果我们使用普通的-(void)postNotification:(NSNotification)notification这种方法来发送通知,那么这个通知就会直接发送到notificationCenter,notificationCenter则会直接将其发送给注册了该通知的观察者。但是如果我们使用NSNotifi
- 479,KVO与NSNotificatioCenter有什么区别?(相同点:两者都是用于监听,且实现原理都是观察者模式,都是一对多(KVO的一对多就是通过addObserver,添加不同的对象)...
枫叶1234
相同点:两者都是用于监听,且实现原理都是观察者模式;都是一对多.不同点:KVO只能用于监听对象属性的变化,并且属性名都是通过NSString来查找,因为都是字符串,手敲过程中容易出错,编译时不会报错;NSNotification的发送监听(post)的操作是我们通过代码控制的,KVO是系统控制的;KVO可以记录新旧值的变化.KVO注意事项基本用法:KVO的使用主要分为3步:注册观察者addObse
- NSNotification观察者移除问题的探究
J丶k
前言最近需求一直挺多的,所以日子过的也就比较“充实”,就在前天偶然看到一个“NSNotification不移除在iOS9.0前后有什么区别的问题”引起了我的兴趣。虽然在使用到NSNotification的时候,我个人都有手动移除通知监听者的编程习惯,因为我知道unsafe_unretained引用当被引用对象在释放时不会自动被置为nil,造成野指针,可能会crash,但我不清楚会和系统版本有关。搜
- iOS-对象间的传值
杯中怎可无酒
iOS-对象间传值传值方式个人把他们分为官方和非官方,可以看出官方版的传值方式均为两个对象之间通过系统特定的方法来进行数据传递,而非官方版则是通过一个中间件来进行数据传递官方版:①delegate代理②block代码块③NSNotification通知④KVC键-值编码⑤KVO键值观察模式⑥属性直接传值非官方版:①单例类②数据缓存(如NSUserDefaults不推荐)delegate它是一种设计
- NSNotificationCenter通知
prician
iOSiosobjective-c
使用观察者模式来实现的用于跨层传递消息的机制参考文章ios消息机制(NSNotification和NSNotificationCenter)透彻理解NSNotificationCenter通知(含实现代码)-掘金NSNotificationCenter@property(class,readonly,strong)NSNotificationCenter*defaultCenter;该属性是获取N
- Flutter开发笔记15 - Flutter基础-组件通信(父子、兄弟,类似iOS中的NSNotification用法)
哈尔滨的酸柠檬
FlutterAndroid
博客原文:https://www.jianshu.com/p/25a85c02d586?tdsourcetag=s_pctim_aiomsg上一篇中讲了如何通过父组件给子组件传值:传送门(方法传参,block回调)这一篇的内容会讲述如何实现:1.父子组件之间的传值方法2.兄弟组件之间的传值方法——eventbus(类似iOS中的NSNotification用法)实现后的效果如下图,实现效果.png
- iOS开发:关于系统dealloc失效的几个原因
Stephen_Xie
大家好,我是“Stephen·谢”,今天简单谈一下系统dealloc方法的一些注意点。dealloc是每个控制器中都有的一个系统方法,由系统响应执行,当当前控制器销毁时,dealloc就会被执行。那么dealloc有什么作用呢?在MRC(手动内存管理)模式下:1、释放自身的实例变量;2、移除观察者KVO;3、停止定时器Timer;4、移除通知NSNotification;5、代理Deleagte置
- NSNotification通知的使用和多线程
Gintok
通知的使用NSNotificationCenter通知中心是iOS程序内部的一种消息广播的实现机制,可以在不同对象之间发送通知进而实现通信,通知中心采用的是一对多的方式,一个对象发送的通知可以被多个对象接收,这一点与KVO机制类似,KVO触发的回调函数也可以被对个对象响应,但代理模式delegate则是一对一的模式,委托对象只能有一个,对象也只能和委托对象通过代理的方式通信。通知机制中比较核心的两
- NSNotificationQueue
guoguojianshu
NSNotificationQueue是操作队列NSNotificationQueue是notificationCenter的缓冲池。如果我们使用普通的-(void)postNotification:(NSNotification*)notification这种方法来发送通知,那么这个通知就会直接发送到notificationCenter,notificationCenter则会直接将其发送给注册
- KVO介绍
深度码农患者
概述KVO是苹果提供的一套事件通知机制,允许对象监听另一个对象特定属性的改变,并在改变时接收到事件。由于KVO的实现机制,所以对属性才会发生作用,一般继承自NSObject的对象都默认支持KVO。KVO和NSNotification都是iOS中对观察者模式的一种实现。区别在于,相对于观察者和被观察者的关系,KVO是一对一的,而不是一对多的。KVO对被监听对象无侵入性,不需要修改其内部代码就可以实现
- iOS之深入解析通知NSNotification的底层原理
╰つ栺尖篴夢ゞ
Objective-C底层原理通知是如何注册的?发送通知的实现原理如何保证通知接收的线程在主线程如何移除通知?通知与runloop关系
一、概念①NSNotificationNSNotification用于描述通知的类,一个NSNotification对象就包含了一条通知的信息,NSNotification对象是不可变的。所以当创建一个通知时通常包含如下属性:@interfaceNSNotification:NSObject@property(readonly,copy)NSNotificationNamename;@proper
- NSNotification-通知
一双鱼jn
通知通知中心NSNotificationCenter通知中心的作用添加观察者通知的发送给通知找到对应的观察者去执行怎么实现的notification_struct.png通知中心存储的结构基本如上图所示每当注册一个通知的时候以通知名为key,存储到一个Table中。value也是一个Table,里面的这个table的key是通知的object参数,value存储的是通知的SEL、observer等
- iOS NSNotification使用及原理实现
FengyunSky
概述NSNotification是苹果提供的一种”同步“单向且线程安全的消息通知机制(并且消息可以携带信息),观察者通过向单例的通知中心注册消息,即可接收指定对象或者其他任何对象发来的消息,可以实现”单播“或者”广播“消息机制,并且观察者和接收者可以完全解耦实现跨层消息传递;同步:消息发送需要等待观察者处理完成消息后再继续执行;单向:发送者只发送消息,接收者不需要回复消息;线程安全:消息发送及接收
- iOS 创建通知、发送通知和移除通知的坑
smile_frank
-(void)viewDidLoad{[superviewDidLoad];//创建通知[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(tongzhi:)name:@"tongzhi"object:nil];}//接收通知并相应的方法-(void)tongzhi:(NSNotification*)noti
- NSNotification理解
wuFANL
NSNotification属于单例模式的一种什么是单例模式:程序在编译时会被实例化一次,提供一个类方法全局调用,会放在内存中一直占有内存,当APP退出时由系统释放内存添加通知,发送通知,移除通知1、发送通知[[NSNotificationCenterdefaultCenter]postNotificationName:@"test0"object:_obj0userInfo:@{@"key":@
- UITextField & UITextView 使用小技巧
ReyZhang
iOS开发小记iosUITextFieldUITextView动态高度获取焦点
前言本文总结了在使用UITextField&UITextView时遇到的一些问题及场景,以及对应的解决方案。目前覆盖的面可能不太全,后面会持续更新…一、监听UITextField内容变化已知三种方式:代理:delegate通知:NSNotification目标动作:addTarget:action:1.代理代理方式只能监听设置了代理的文本框。没有设置代理的文本框不能进行监听。设置代理self.te
- iOS中NSNotificationCenter规则总结
鸢飞阿诗玛
单纯使用(void)postNotification:(NSNotification*)notification;(void)addObserver:(id)observerselector:(SEL)aSelectorname:(nullableNSNotificationName)aNameobject:(nullableid)anObject;监听方法和发送方法在同一线程监听方法执行顺序与监
- 降低崩溃率之--通知造成NSNotification crash
梁炜东
当一个对象添加了notification之后,如果dealloc的时候,仍然持有notification,就会出现NSNotification类型的crash。NSNotification类型的crash多产生于程序员写代码时候犯疏忽,在NSNotificationCenter添加一个对象为observer之后,忘记了在对象dealloc的时候移除它。所幸的是,苹果在iOS9之后专门针对于这种情况
- iOS小记--_defaultCenterWithoutCreating
原鸣清
截屏2021-09-1510.54.57.png很遗憾,上面图中的Crash,我没有搞明白原因,也不知道如何解决。记录下这里有两个目的,一为以后有可能解决留下哥引子;更重要的是如果有大神知道原因,还请不吝赐教。在搜索这个问题的时候,找到两篇关于NSNotification非常不错的文章,也链在这里。一文全解iOS通知机制上午中9个问题的答案
- 通知同步异步的验证,通知的重定向
孙优秀丶Unique
通知同步异步的验证,通知的重定向验证NSNotification的同步和异步问题我们先来这样发送一个通知-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event{SCXNotiTest*noti=[SCXNotiTestnew];self.noti=noti;dispatch_async(dispatch_get_global_que
- ReactiveObjC 监听通知遇到的坑
JasonFive
RAC功能很多,也很强大,但是在使用监听通知的时候,遇到一个问题,就是监听不能被释放:[[[NSNotificationCenterdefaultCenter]rac_addObserverForName:UIApplicationWillEnterForegroundNotificationobject:nil]subscribeNext:^(NSNotification*_Nullablex)
- Swift 通知实现
江河_ios
发通知不带参数NotificationCenter.default.post(name:Notification.Name("name"),object:nil)带参数值NotificationCenter.default.post(name:NSNotification.Name("changeColor"),object:nil,userInfo:["color":"green"])接收通知N
- ReactiveCocoa(RAC)初探
_相信自己_
Notification通知[[[NSNotificationCenterdefaultCenter]rac_addObserverForName:UIKeyboardWillShowNotificationobject:nil]subscribeNext:^(NSNotification*_Nullablex){NSLog(@"%@",x);}];ControlEvent事件[[self.log
- iOS播放音频
whereandhere
1.播放网络音频NSURL*url=[NSURLURLWithString:MP3URL];AVPlayerItem*songItem=[[AVPlayerItemalloc]initWithURL:url];self.avplayer=[[AVPlayeralloc]initWithPlayerItem:songItem];[self.avplayerplay];[[NSNotification
- iOS键盘弹出时动画时间问题
Yadea前端杂记
iOS键盘弹出动画问题今天在写键盘弹出时遇见一个问题。监听UIKeyboardWillShowNotification通知让Label做一个移动的动画,指定duration为15,但动画实际完成时间却与键盘弹出时间一致。-(void)keyboardWillShow:(NSNotification*)notification{[UIViewanimateWithDuration:15animati
- Maven
Array_06
eclipsejdkmaven
Maven
Maven是基于项目对象模型(POM), 信息来管理项目的构建,报告和文档的软件项目管理工具。
Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目发文时使用 Maven,而且公司
- ibatis的queyrForList和queryForMap区别
bijian1013
javaibatis
一.说明
iBatis的返回值参数类型也有种:resultMap与resultClass,这两种类型的选择可以用两句话说明之:
1.当结果集列名和类的属性名完全相对应的时候,则可直接用resultClass直接指定查询结果类
- LeetCode[位运算] - #191 计算汉明权重
Cwind
java位运算LeetCodeAlgorithm题解
原题链接:#191 Number of 1 Bits
要求:
写一个函数,以一个无符号整数为参数,返回其汉明权重。例如,‘11’的二进制表示为'00000000000000000000000000001011', 故函数应当返回3。
汉明权重:指一个字符串中非零字符的个数;对于二进制串,即其中‘1’的个数。
难度:简单
分析:
将十进制参数转换为二进制,然后计算其中1的个数即可。
“
- 浅谈java类与对象
15700786134
java
java是一门面向对象的编程语言,类与对象是其最基本的概念。所谓对象,就是一个个具体的物体,一个人,一台电脑,都是对象。而类,就是对象的一种抽象,是多个对象具有的共性的一种集合,其中包含了属性与方法,就是属于该类的对象所具有的共性。当一个类创建了对象,这个对象就拥有了该类全部的属性,方法。相比于结构化的编程思路,面向对象更适用于人的思维
- linux下双网卡同一个IP
被触发
linux
转自:
http://q2482696735.blog.163.com/blog/static/250606077201569029441/
由于需要一台机器有两个网卡,开始时设置在同一个网段的IP,发现数据总是从一个网卡发出,而另一个网卡上没有数据流动。网上找了下,发现相同的问题不少:
一、
关于双网卡设置同一网段IP然后连接交换机的时候出现的奇怪现象。当时没有怎么思考、以为是生成树
- 安卓按主页键隐藏程序之后无法再次打开
肆无忌惮_
安卓
遇到一个奇怪的问题,当SplashActivity跳转到MainActivity之后,按主页键,再去打开程序,程序没法再打开(闪一下),结束任务再开也是这样,只能卸载了再重装。而且每次在Log里都打印了这句话"进入主程序"。后来发现是必须跳转之后再finish掉SplashActivity
本来代码:
// 销毁这个Activity
fin
- 通过cookie保存并读取用户登录信息实例
知了ing
JavaScripthtml
通过cookie的getCookies()方法可获取所有cookie对象的集合;通过getName()方法可以获取指定的名称的cookie;通过getValue()方法获取到cookie对象的值。另外,将一个cookie对象发送到客户端,使用response对象的addCookie()方法。
下面通过cookie保存并读取用户登录信息的例子加深一下理解。
(1)创建index.jsp文件。在改
- JAVA 对象池
矮蛋蛋
javaObjectPool
原文地址:
http://www.blogjava.net/baoyaer/articles/218460.html
Jakarta对象池
☆为什么使用对象池
恰当地使用对象池化技术,可以有效地减少对象生成和初始化时的消耗,提高系统的运行效率。Jakarta Commons Pool组件提供了一整套用于实现对象池化
- ArrayList根据条件+for循环批量删除的方法
alleni123
java
场景如下:
ArrayList<Obj> list
Obj-> createTime, sid.
现在要根据obj的createTime来进行定期清理。(释放内存)
-------------------------
首先想到的方法就是
for(Obj o:list){
if(o.createTime-currentT>xxx){
- 阿里巴巴“耕地宝”大战各种宝
百合不是茶
平台战略
“耕地保”平台是阿里巴巴和安徽农民共同推出的一个 “首个互联网定制私人农场”,“耕地宝”由阿里巴巴投入一亿 ,主要是用来进行农业方面,将农民手中的散地集中起来 不仅加大农民集体在土地上面的话语权,还增加了土地的流通与 利用率,提高了土地的产量,有利于大规模的产业化的高科技农业的 发展,阿里在农业上的探索将会引起新一轮的产业调整,但是集体化之后农民的个体的话语权 将更少,国家应出台相应的法律法规保护
- Spring注入有继承关系的类(1)
bijian1013
javaspring
一个类一个类的注入
1.AClass类
package com.bijian.spring.test2;
public class AClass {
String a;
String b;
public String getA() {
return a;
}
public void setA(Strin
- 30岁转型期你能否成为成功人士
bijian1013
成功
很多人由于年轻时走了弯路,到了30岁一事无成,这样的例子大有人在。但同样也有一些人,整个职业生涯都发展得很优秀,到了30岁已经成为职场的精英阶层。由于做猎头的原因,我们接触很多30岁左右的经理人,发现他们在职业发展道路上往往有很多致命的问题。在30岁之前,他们的职业生涯表现很优秀,但从30岁到40岁这一段,很多人
- [Velocity三]基于Servlet+Velocity的web应用
bit1129
velocity
什么是VelocityViewServlet
使用org.apache.velocity.tools.view.VelocityViewServlet可以将Velocity集成到基于Servlet的web应用中,以Servlet+Velocity的方式实现web应用
Servlet + Velocity的一般步骤
1.自定义Servlet,实现VelocityViewServl
- 【Kafka十二】关于Kafka是一个Commit Log Service
bit1129
service
Kafka is a distributed, partitioned, replicated commit log service.这里的commit log如何理解?
A message is considered "committed" when all in sync replicas for that partition have applied i
- NGINX + LUA实现复杂的控制
ronin47
lua nginx 控制
安装lua_nginx_module 模块
lua_nginx_module 可以一步步的安装,也可以直接用淘宝的OpenResty
Centos和debian的安装就简单了。。
这里说下freebsd的安装:
fetch http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar zxvf lua-5.1.4.tar.gz
cd lua-5.1.4
ma
- java-14.输入一个已经按升序排序过的数组和一个数字, 在数组中查找两个数,使得它们的和正好是输入的那个数字
bylijinnan
java
public class TwoElementEqualSum {
/**
* 第 14 题:
题目:输入一个已经按升序排序过的数组和一个数字,
在数组中查找两个数,使得它们的和正好是输入的那个数字。
要求时间复杂度是 O(n) 。如果有多对数字的和等于输入的数字,输出任意一对即可。
例如输入数组 1 、 2 、 4 、 7 、 11 、 15 和数字 15 。由于
- Netty源码学习-HttpChunkAggregator-HttpRequestEncoder-HttpResponseDecoder
bylijinnan
javanetty
今天看Netty如何实现一个Http Server
org.jboss.netty.example.http.file.HttpStaticFileServerPipelineFactory:
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast(&quo
- java敏感词过虑-基于多叉树原理
cngolon
违禁词过虑替换违禁词敏感词过虑多叉树
基于多叉树的敏感词、关键词过滤的工具包,用于java中的敏感词过滤
1、工具包自带敏感词词库,第一次调用时读入词库,故第一次调用时间可能较长,在类加载后普通pc机上html过滤5000字在80毫秒左右,纯文本35毫秒左右。
2、如需自定义词库,将jar包考入WEB-INF工程的lib目录,在WEB-INF/classes目录下建一个
utf-8的words.dict文本文件,
- 多线程知识
cuishikuan
多线程
T1,T2,T3三个线程工作顺序,按照T1,T2,T3依次进行
public class T1 implements Runnable{
@Override
 
- spring整合activemq
dalan_123
java spring jms
整合spring和activemq需要搞清楚如下的东东1、ConnectionFactory分: a、spring管理连接到activemq服务器的管理ConnectionFactory也即是所谓产生到jms服务器的链接 b、真正产生到JMS服务器链接的ConnectionFactory还得
- MySQL时间字段究竟使用INT还是DateTime?
dcj3sjt126com
mysql
环境:Windows XPPHP Version 5.2.9MySQL Server 5.1
第一步、创建一个表date_test(非定长、int时间)
CREATE TABLE `test`.`date_test` (`id` INT NOT NULL AUTO_INCREMENT ,`start_time` INT NOT NULL ,`some_content`
- Parcel: unable to marshal value
dcj3sjt126com
marshal
在两个activity直接传递List<xxInfo>时,出现Parcel: unable to marshal value异常。 在MainActivity页面(MainActivity页面向NextActivity页面传递一个List<xxInfo>): Intent intent = new Intent(this, Next
- linux进程的查看上(ps)
eksliang
linux pslinux ps -llinux ps aux
ps:将某个时间点的进程运行情况选取下来
转载请出自出处:http://eksliang.iteye.com/admin/blogs/2119469
http://eksliang.iteye.com
ps 这个命令的man page 不是很好查阅,因为很多不同的Unix都使用这儿ps来查阅进程的状态,为了要符合不同版本的需求,所以这个
- 为什么第三方应用能早于System的app启动
gqdy365
System
Android应用的启动顺序网上有一大堆资料可以查阅了,这里就不细述了,这里不阐述ROM启动还有bootloader,软件启动的大致流程应该是启动kernel -> 运行servicemanager 把一些native的服务用命令启动起来(包括wifi, power, rild, surfaceflinger, mediaserver等等)-> 启动Dalivk中的第一个进程Zygot
- App Framework发送JSONP请求(3)
hw1287789687
jsonp跨域请求发送jsonpajax请求越狱请求
App Framework 中如何发送JSONP请求呢?
使用jsonp,详情请参考:http://json-p.org/
如何发送Ajax请求呢?
(1)登录
/***
* 会员登录
* @param username
* @param password
*/
var user_login=function(username,password){
// aler
- 发福利,整理了一份关于“资源汇总”的汇总
justjavac
资源
觉得有用的话,可以去github关注:https://github.com/justjavac/awesome-awesomeness-zh_CN 通用
free-programming-books-zh_CN 免费的计算机编程类中文书籍
精彩博客集合 hacke2/hacke2.github.io#2
ResumeSample 程序员简历
- 用 Java 技术创建 RESTful Web 服务
macroli
java编程WebREST
转载:http://www.ibm.com/developerworks/cn/web/wa-jaxrs/
JAX-RS (JSR-311) 【 Java API for RESTful Web Services 】是一种 Java™ API,可使 Java Restful 服务的开发变得迅速而轻松。这个 API 提供了一种基于注释的模型来描述分布式资源。注释被用来提供资源的位
- CentOS6.5-x86_64位下oracle11g的安装详细步骤及注意事项
超声波
oraclelinux
前言:
这两天项目要上线了,由我负责往服务器部署整个项目,因此首先要往服务器安装oracle,服务器本身是CentOS6.5的64位系统,安装的数据库版本是11g,在整个的安装过程中碰到很多的坑,不过最后还是通过各种途径解决并成功装上了。转别写篇博客来记录完整的安装过程以及在整个过程中的注意事项。希望对以后那些刚刚接触的菜鸟们能起到一定的帮助作用。
安装过程中可能遇到的问题(注
- HttpClient 4.3 设置keeplive 和 timeout 的方法
supben
httpclient
ConnectionKeepAliveStrategy kaStrategy = new DefaultConnectionKeepAliveStrategy() {
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
long keepAlive
- Spring 4.2新特性-@Import注解的升级
wiselyman
spring 4
3.1 @Import
@Import注解在4.2之前只支持导入配置类
在4.2,@Import注解支持导入普通的java类,并将其声明成一个bean
3.2 示例
演示java类
package com.wisely.spring4_2.imp;
public class DemoService {
public void doSomethin