NSNotification相关
来源:互联网 发布:vmware linux nat上网 编辑:程序博客网 时间:2024/05/20 07:53
addObserver:selector:name:object:
Adds an entry to the receiver’s dispatch table with an observer, a notification selector and optional criteria: notification name and sender.
Parameters
- notificationObserver
Object registering as an observer. This value must not be
nil
.指定观察者是谁,此参数不能为空,一般为self
- notificationSelector
Selector that specifies the message the receiver sends notificationObserver to notify it of the notification posting. The method specified by notificationSelector must have one and only one argument (an instance of
NSNotification
).观察者要响应的方法,此方法必须要有而且只有一个参数'NSNotification'
- notificationName
The name of the notification for which to register the observer; that is, only notifications with this name are delivered to the observer.
If you pass
nil
, the notification center doesn’t use a notification’s name to decide whether to deliver it to the observer.通知的名称,在通知中心注册的名字
- notificationSender
The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer.
If you pass
nil
, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.谁发送的这个通知postNotificationName:object:userInfo:
Creates a notification with a given name, sender, and information and posts it to the receiver.
- (void)postNotificationName:(NSString *)notificationName object:(id)notificationSender userInfo:(NSDictionary*)userInfo通知中心的内容Parameters
- notificationName
The name of the notification.
- notificationSender
The object posting the notification.
- userInfo
Information about the the notification. May be
nil
.
//点击按钮
- (IBAction)btnPressed:(id)sender
{
[[NSNotificationCenterdefaultCenter] postNotificationName:@"hello"object:niluserInfo:[NSDictionarydictionaryWithObject:@"YES"forKey:@"result"]];
}
//注册通知
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(hello:)name:@"hello"object:nil];
- (void)hello:(NSNotification *)sender
{
NSDictionary *dict = [sender userInfo];
NSString *str = [dict objectForKey:@"result"];
NSLog(@"str = %@",str);
}
//NSNotification的使用
@interface NSNotification :NSObject <NSCopying,NSCoding>
- (NSString *)name;
- (id)object;
- (NSDictionary *)userInfo;
@end
- NSNotification相关
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification example
- NSNotification详解
- 通知 NSNotification
- sed直接替换文本文件(sed与awk是正则表达的俩大神器)
- mysql 基本操作
- SQL 存储过程的事务
- 遇到的一个关于IFS的问题
- myeclipse快捷键大全
- NSNotification相关
- POJ 2426 Interesting Housing Problem (最大费用最大流)
- Oracle常用命令
- iphone开发十几个实用demo合集
- asp.net服务器控件与html服务器控件的区别
- 使用Ctrl+Enter提交表单
- php 执行shell命令的函数
- hdu 1161 Eddy's mistakes
- android仿path下拉及刷新