zoukankan      html  css  js  c++  java
  • ios NSNotificationCenter 消息的收发

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

    1 [[NSNotificationCenter defaultCenter] postNotificationName:@"WECHARTPAY"object:nil];

    参数介绍:

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

             object:传递的参数

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

    1 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
    2 [notificationCenter addObserver:self selector:@selector(handlePayFinished:) name:@"WECHARTPAY" object:nil] ;

    参数介绍:

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

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

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

    收消息处理方法:

    1 - (void)handlePayFinished:(NSNotification *)notification
    2 {
    3   id obj = [notification object];//获取到传递的对象
    4 }
  • 相关阅读:
    为上次写的框架加了一个辅助功能
    复制文件夹下所有文件
    进制之间的相互转换
    c# 修改appConfig文件节点
    GUID
    太悲哀了
    poj2411 Mondriaan's Dream
    poj3311 Hie with the Pie
    HDU3001 Travelling
    luogu p2622关灯问题II
  • 原文地址:https://www.cnblogs.com/codemakerhj/p/4723344.html
Copyright © 2011-2022 走看看