首页 > 代码库 > IOS中NSNotification使用笔记

IOS中NSNotification使用笔记

1 基本用法

添加观察(可能很多页面)


[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(changeIntlCode:)name:NOTIFICATION_SUCCESS_SELECT_INTLCODEobject:nil];


发出通知(可能只有一个页面)

[[NSNotificationCenterdefaultCenter] postNotificationName:NOTIFICATION_SUCCESS_SELECT_INTLCODEobject:niluserInfo:[NSDictionarydictionaryWithObject:model forKey:@"selectedIntlCodeModel"]];


在 dealloc中移除监听

[[NSNotificationCenter defaultCenter] removeObserver:self name:NOTIFICATION_SUCCESS_SELECT_INTLCODE object:nil];