通知机制

通知

  1.建立通知中心

    NSNotificationCenter *center = [NSNotificationCenterdefaultCenter];

  2.利用通知中心发通知

    2.1创建一个通知对象

    NSNotification *note = [NSNotificationnotificationWithName:@"tech_new"object:tx];

    2.2利用通知中心,将这则通知发出去   

    [center postNotification:note];

  3.监听通知中心发出的通知

  [center addObserver:p selector:@selector(gotNews) name:@"tech_new" object:tx];

  4.创建通知对象的时候可以带上一个属性useinfo  ----->是这则通知的详情

      NSNotification *note = [NSNotificationnotificationWithName:@"tech_new"object:tx userInfo:@{

                 @"title" : @"今天天气真好",

                  @"source" : @"腾讯网"

                                }];

  5.通知不要重复添加。

  6.移除通知 (arc不用移除)

  [ceter remove:p];

  [ceter remove:p name:@"tech_news" object:tx];

posted @ 2013-12-05 12:35  nx的封装  阅读(163)  评论(0编辑  收藏  举报