zoukankan      html  css  js  c++  java
  • 关于iOS开发中NSNotification

    简单的总结一下通知,代理,通知,还有block都是属于类之间通信的机制,今天写点通知相关,原谅我这么菜还写博客,不过,会越来越好的

    1.注册通知,或者说是给哪里加通知,加观察者,也就是接受通知的东西,设置接受通知的名字,还有接受到通知后调用的方法;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(first:) name:@"first" object:nil ];

    2.发送通知,这步就是发送一个通知,并且带了参数,以及通知的名字,以便对应的观察者进行接收;

    [[NSNotificationCenter defaultCenter] postNotificationName:@"first" object:nil userInfo:@{@"url":@"wangyao"}];

    3.写函数,这个就是掉的函数,执行你想执行的;

    - (void)first:(NSNotification *)noti
    {
        NSLog(@"haha%@",noti.userInfo);
    }

    4.用到通知的viewcontroller一定要写这个,因为通知其实挺占用资源的,所以界面销毁的时候,记得把通知也移除。

    - (void)dealloc
    {
        [[NSNotificationCenter defaultCenter]removeObserver:self];
        NSLog(@"delloc");
    }

  • 相关阅读:
    Unix系统中system函数的返回值
    vim 插件 for gbasic
    arch初认识
    TI IPNC Web网页之进阶修改
    Ti IPNC Web网页之ActiveX控件
    TI IPNC Web网页之网页修改教程
    OI,再见
    [OI]省选前模板整理
    OI刷题录——hahalidaxin
    51nod 小Z的trie(Trie+广义SAM)
  • 原文地址:https://www.cnblogs.com/YaoWang/p/5282776.html
Copyright © 2011-2022 走看看