zoukankan      html  css  js  c++  java
  • NSNotificationCenter 传递带参数的通知

    NSNotificationCenter  在  init里面注册这个通知,

    NSString* const str = @"FuckMe";

       [[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(on:)   name:str object:nil];

    在dealloc里面移除这个通知的注册: 

       [[NSNotificationCenter  defaultCenterremoveObserver:self  name:str object:nil];

    以上为不带参数的通知

    一般在使用NSNotificationCenter的时候不使用参数,但是有些时候需要使用参数。

    传递参数

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

    接收参数并获取传递的参数

     

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

    object:传递的参数

     

    - (void) test:(NSNotification*) notification

    {

        searchFriendArrary = [notification object];//通过这个获取到传递的对象

  • 相关阅读:
    表格维护:弹出
    表格联动
    表单查询
    浅谈分治 —— 洛谷P1228 地毯填补问题 题解
    The Captain 题解
    网课集训记
    2020-1-20寒假集训记
    博客使用声明
    JZOJ P5829 string 线段树
    线段树--CF438D The Child and Sequence
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2662349.html
Copyright © 2011-2022 走看看