通知
通知模式:⼀一个对象能够给其他任意数量的对象⼲⼴广播信息。对象之间可以没有耦合关系。
NSNotification(通知),封装了要⼲⼴广播的信息。 NSNotificationCenter(通知中⼼心),管理注册接收消息对象,⼲⼴广播消息。 observer(观察者),需要监测⼲⼴广播信息的对象,即接收信息的对象。
使用方法
接收信息对象在通知中⼼心进⾏行注册,包括:信息名称、接收信息时的处理⽅方法。
对象通过通知中⼼心⼲⼴广播信息,包括:信息名称、信息内容。
已经注册过的对象如果不需要接收信息时,在通知中⼼心注销。
方法
注册: [[NSNotificationCenter defaultCenter] addObserver:注册对象selector:@selector(⽅方法名) name:信息名称 object:nil]
注销: [[NSNotificationCenter defaultCenter] removeObserver:注销对象 name:信息名称 object:nil];
发送信息:[[NSNotificationCenter defaultCenter] postNotificationName:信息名称 object:发信息对象 userInfo:发送消息时 传递的信息];
==================
实现换肤
1.首先创建4个继承于ViewController和一个继承于UITabBarController的RootViewController 把RootViewController作为window的根视图控制器
===
在RootViewController.m文件里
=====
在FourViewController.m发送通知
=====
在OneViewController.m和TwoViewController.m和ThirdViewController.m中 哪里都都可以接到通知
三个视图通过以上方法都可以接到通知消息
======
重点换肤 — 在AppDelegate.m中