zoukankan      html  css  js  c++  java
  • ios--->NSNotificationCenter传值

    object实现
    //在发送通知时设置object参数
    [[NSNotificationCenter defaultCenter] 
    postNotificationName:@"ThisIsANoticafication" object:@{@"parameter1":@"1",@"parameter2":@"2"}];
    
    //这里传入了一个字典,那么如何在接收通知的时候得到这个字典呢
    [[NSNotificationCenter defaultCenter] 
    addObserver:self selector:@selector(getNotificationAction:) name:@"ThisIsANoticafication" object:nil];
    
    
    //方法
    - (void)getNotificationAction:(NSNotification *)notification{
        NSDictionary * infoDic = [notification object];
        // 这样就得到了我们在发送通知时候传入的字典了
    }
    
    userinfo实现
    //发通知
    NSDictionary *myDictionary = [NSDictionary dictionaryWithObject:@"sendValue" forKey:@"sendKey"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"myNotice" object:nil userInfo:myDictionary];
        
    //接受通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noticeMethod:) name:@"myNotice" object:nil];
    
    //调用方法,接受信息。
    - (void)noticeMethod:(NSNotification *)notification
    {
         NSString *getsendValue = [[notification userInfo] valueForKey:@"sendKey"];
    }
    
  • 相关阅读:
    flash
    应用缓存
    音频和视频
    拖拽借口
    地理定位接口
    表单元素
    jquery常见用法
    jquery ajax 模板
    Ubuntu下Lucene环境搭配
    小絮叨
  • 原文地址:https://www.cnblogs.com/frankltf/p/7844327.html
Copyright © 2011-2022 走看看