StupidBeauty
Read times:818Posted at:Wed Oct 16 04:49:26 2013
- no title specified

转载:详解iPhone开发之消息通信机制NSNotificationCenter

IOS开发中,对象之间通信可使用NSNotificationCenter,用起来类似于QT的信号/信号槽。

http://mobile.51cto.com/iphone-284733.htm

亮点:

设置通知,就是说要在什么地方(哪个类)接受通知,一般在初始化中做。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test:) name:@"test" object:nil];

我仅对以上参数做以说明:addObserver 这个是观察者,就是说 在什么地方接收通知;

selector 这个是收到通知后,调用何种方法;

name: 这个是通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。

发送通知,就是说此时要调用观察者处的方法。

[[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:searchFriendArray];

未知美人

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4