NSNotificationCenter 传递带参数的通知

NSNotificationCenter  在  init里面注册这个通知,

NSString* const str = @"FuckMe";

   [[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(on:)   name:str object:nil];

在dealloc里面移除这个通知的注册: 

   [[NSNotificationCenter  defaultCenterremoveObserver:self  name:str object:nil];

以上为不带参数的通知

 

一般在使用NSNotificationCenter的时候不使用参数,但是有些时候需要使用参数。

传递参数

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

接收参数并获取传递的参数

 

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

object:传递的参数

 

- (void) test:(NSNotification*) notification

{

    searchFriendArrary = [notification object];//通过这个获取到传递的对象

posted on 2012-08-29 16:51  easonoutlook  阅读(18867)  评论(1编辑  收藏  举报