NSNotification通知放的位置

viewwillappear 、 viewwilldisappear     和   viewdidload、dealloc

如果 是详情页面 跳转到详情页面或者同一个页面类型跳转,这个时候 一定得使用viewwillappear 不然上一个页面也会出现响应通知。


object:携带数据。并不是指定对象接受。可以接受 nsarray等。

userInfo:代表传值

方法1:[[NSNotificationCenter defaultCenter] postNotificationName:@"First"object:@"博客园"];

方法2:

NSDictionary*dict=[[NSDictionary alloc]initWithObjects:@[@"keso"] forKeys:@[@"key"]];

[[NSNotificationCenter defaultCenter] postNotificationName:@"Second"object:@"http://www.cnblogs.com"userInfo:dict];


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

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


-(void)notificationFirst:(NSNotification *)notification{

NSString*name=[notification name];

NSString*object=[notificationobject];

NSLog(@"名称:%@----对象:%@",name,object);

}-(void)notificationSecond:(NSNotification *)notification{

NSString*name=[notification name];

NSString*object=[notification object];

NSDictionary*dict=[notification userInfo];

NSLog(@"名称:%@----对象:%@",name,object);

NSLog(@"获取的值:%@",[dict objectForKey:@"key"]);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容