标签:
// // 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
标签:
原文地址:http://www.cnblogs.com/BJTUzhengli/p/5095034.html