首页 > 其他 > 详细

2016-1-2通知机制的学习 2:代码实现

时间:2016-01-02 20:15:38      阅读:248      评论:0      收藏:0      [点我收藏+]
//
//  ViewController.m
//  通知机制
//
//  Created by Mac on 16/1/2.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "ViewController.h"
#import "CZPerson.h"
#import "CZGroup.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CZPerson *p1=  [[CZPerson alloc]init];
    p1.name = @"z";
    CZPerson *p2 = [[CZPerson alloc]init];
    p2.name = @"h";
    
    CZGroup *g1 = [[CZGroup alloc] init];
    g1.name = @"g1";
    CZGroup *g2 = [[CZGroup alloc]init];
    g2.name = @"g2";
//   通知中心
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
//    初始化一个通知
    NSNotification *n1 = [NSNotification notificationWithName:@"nongniunai" object:g1 userInfo:@{@"count":@2,@"tx":@"哈哈"}];
    //    订阅通知
    [center addObserver:p1 selector:@selector(shouniunai:) name:@"nongniunai" object:g1];
//    发送一个通知
    [center postNotification:n1];

    
//    发布通知
    
    }

@end

 

2016-1-2通知机制的学习 2:代码实现

原文:http://www.cnblogs.com/BJTUzhengli/p/5095034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!