廣播三要素
廣播中心
發(fā)起人
接收者
總體結(jié)構(gòu)
1、接收者像廣播中心注冊(cè)
2您炉、廣播中心定義方法
3、發(fā)起人發(fā)送廣播
AClass(發(fā)起人)
[[NSNotificationCenter defaultCenter]posNotificationName:@"廣播名稱" object]
BClass(接收者)
1.注冊(cè)廣播
[NSNotificationCenter deaultCenter]addObserver:self selector:@selector(調(diào)用方法名稱)
name:@"廣播名稱" object:nil];
2.實(shí)現(xiàn)廣播方法
-(void)調(diào)用方法{
}
3.銷毀廣播
[[NSNotificationCenter defaultCenter]removeObserver:self name@"廣播名稱" object:nil];
發(fā)送帶有參數(shù)的廣播
[NSNotification defaultCenter]postNotificationName:@"廣播名稱" object:傳遞對(duì)象 userInfo:傳遞一個(gè)字典參數(shù)];
接收帶有參數(shù)的廣播:
@selector(方法名:)役电,加上了冒號(hào)
-(void)實(shí)現(xiàn)方法:(NSNotification*)notif{
notif.object;
notif.userInfo;
}