zoukankan      html  css  js  c++  java
  • NSNotificationCenter机制

    作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的.

    注册通知:即要在什么地方接受消息

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

          参数介绍:

              addObserver: 观察者,即在什么地方接收通知;

            selector: 收到通知后调用何种方法;

            name: 通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。

    发送通知:调用观察者处的方法。

               [[NSNotificationCenter defaultCenter] postNotificationName:@"mytest" object:searchFriendArray];

              参数:

             postNotificationName:通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。

                     object:传递的参数

    注册方法的写法:

    - (void) mytest:(NSNotification*) notification

    {

       id obj = [notification object];//获取到传递的对象

    附:注册键盘升启关闭消息//键盘升起 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

  • 相关阅读:
    windows 环境下 eclipse + maven + tomcat 的 hello world 创建和部署
    使用IntelliJ IDEA 14和Maven创建java web项目
    使用Spring JDBCTemplate简化JDBC的操作
    CSS颜色代码 颜色值 颜色名字大全
    mysql创建数据库命令
    win64位安装python-mysqldb1.2.3
    UVA11426 欧拉函数
    关于gcd的几个问题
    POI2007_zap 莫比乌斯反演
    BZOJ2005 莫比乌斯反演
  • 原文地址:https://www.cnblogs.com/fuland/p/3665562.html
Copyright © 2011-2022 走看看