update3 iOS7 viewcontrol内接收系统广播的

2016-06-21  本文已影响21人  冰风47

需要用到的组件:
viewcontroler, NSNotificationCenter.

  1. 在view controler内重载viewWillAppear( 我们将要在视图没有出现之前就把广播绑定好 )

  2. 调用NSNotification的类方法 defaultCenter

  3. 自定义好广播回调函数

  4. 选好需要接收的广播名称

  5. 调用defaultCenter的方法 addObserver, 加入3,4项内的参数即可

  6. object参数填入nil. (木有指向性对象, 我想接所有的广播~)

例:


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                              selector:@selector(uicontentSizeChangedReceiver:)
                                                  name:UIContentSizeCategoryDidChangeNotification
                                                object:nil];
}

- (void)userPreferredFont
{
    self.body.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
    self.headline.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
}

上一篇下一篇

猜你喜欢

热点阅读