geraldzhang

业精于勤荒于嬉,行成于思毁于随!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: 订阅 订阅 :: 管理 ::

 NSNotification

  个人觉得用这个东西在不同的viewcontroller间传东西很方便的

  发消息

  [[NSNotificationCenter defaultCenter] postNotificationName:@"popView"/*消息名字,在添加监听时会用到*/       object:@"ShowHomeLineViewController"/*传的参数,多个参数就可以用数组啦*/];

  收消息

  1、添加监听:

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Show:)/*收到消息后的响应函数*/ name:@"popView"/*消息名字,在发消息时  指定的*/ object:nil];

  2、消息处理(实现前面的Show:函数)

  -(void)Show:(NSNotification*)notification

  {

  NSString* str = (NSString*)[notification object];//这里取出刚刚从过来的字符串

  }

  3、不要忘记移除监听

  [[NSNotificationCenter defaultCenter] removeObserver:self name:@"popView" object:nil];

posted on 2011-09-21 15:18  geraldzhang  阅读(273)  评论(0编辑  收藏  举报