美文网首页
update3 iOS7 viewcontrol内接收系统广播的

update3 iOS7 viewcontrol内接收系统广播的

作者: 冰风47 | 来源:发表于2016-06-21 18:32 被阅读21次

    需要用到的组件:
    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];
    }
    
    

    相关文章

      网友评论

          本文标题:update3 iOS7 viewcontrol内接收系统广播的

          本文链接:https://www.haomeiwen.com/subject/hmugdttx.html