在你需要传值的地方:
//创建通知
NSNotification *notification =[NSNotification notificationWithName:@"tongzhi" object:nil userInfo:dic];
//通过通知中心发送通知
[[NSNotificationCenter defaultCenter] postNotification:notification];
注意:值用dic(字典),字典里面value只能装OC对象,你可以将c类型转换为oc类型。
在另外的一个类或者地方
//注册通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:) name:@"tongzhi" object:nil];
实现方法就不用我说了吧。
千万记得最后一个:
- (void)dealloc{
//移除通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"tongzhi" object:nil];
}
别忘记了