• 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];//获取到传递的对象

  • 相关阅读:
    UIView的clipsToBounds属性,layoutSubViews及触摸事件传递(默认情况下)总结
    ISO中运行时简单使用及KVC补充
    IOS中UISearchBar的使用
    oc的block
    oc的协议(protocol)
    oc的分类category
    oc内存的理解
    oc笔记(转载)
    oc对象中属性总结
    servlet,struts1,struts2,spring
  • 原文地址:https://www.cnblogs.com/baozou/p/3317781.html
Copyright © 2020-2023  润新知