宏定義:
#define NAME @"name"
ViewController.m
[[NSNotificationCenter defaultCenter]
selector:@selector(Action:) //通知方法
name:NAME//如果名字不是宏定義請檢查你的名字是否相同
object:nil];
-(void)Action:(NSNotification *)objct//注意這裏是NSNotification
{
NSDictionary *dic=objct.userInfo;
NSLog(@"name=%@",dic[@"Name"]);
}
ValueOf.m
通知方法介紹:
-(void)postNotificationName:(NSString *)notificationName//通知的名字
object:(id)notificationSender //那個對象
userInfo:(NSDictionary *)userInfo//通知的內容
在需要出發或指定地方的地方添加通知:
NSDictionary *dictionary2=@{@"Name":@"Lan"};
[[NSNotificationCenter defaultCenter]
postNotificationName:NAME //建議通知是使用宏定義
userInfo:dictionary2];//傳值對象