• NSNotificationCenter


    - (void)viewDidLoad {

        [super viewDidLoad];

        

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

        btn.frame = CGRectMake(100, 100, 100, 50);

        btn.backgroundColor = [UIColor grayColor];

        [btn setTitle:@"click me" forState:UIControlStateNormal];

        [btn addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];

        

        [self.view addSubview:btn];

        

        // 注册消息

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNoticeMessage:) name:@"test" object:@"notice-recieve"];

    }

     

    -(void)clickAction:(id)sender

    {

        // 能接受消息

        [[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:@"notice-recieve"];

        

        // 不能接收到消息,object 对象不一致

        [[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:@"notice-recieve111"];

    }

     

    // 处理消息

    -(void)handleNoticeMessage:(id)sender

    {

        NSLog(@"handleNoticeMessage sender = %@", sender);

    }

     

    -(void)viewWillDisappear:(BOOL)animated

    {

        // 移除通知

        [[NSNotificationCenter defaultCenter]removeObserver:self];

    }

  • 相关阅读:
    cookie操作和代理
    发起post请求
    scrapy核心组件
    爬取多个url页面数据--手动实现
    scrapy之持久化存储
    selenium + phantomJs
    scrapy框架简介和基础使用
    校验验证码 实现登录验证
    beautifulsoup解析
    xpath
  • 原文地址:https://www.cnblogs.com/xiangjune/p/5190798.html
Copyright © 2020-2023  润新知