通知的用法:
1,注册通知
NSNotificationCenter *center = [NSNotificationCenterdefaultCenter];
[center addObserver:selfselector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotificationobject:nil];
2,通知收到的处理方法
- (void)applicationDidBecomeActive: (NSNotification *)notification
{
notification是可以获取发送UIApplicationDidBecomeActiveNotification通知的对象传送过来的数据(包括object和userInfo)
}
3,发送通知的方法:
postNotificationName:UIApplicationDidBecomeActiveNotification object: userInfo:(自定义的字典对象,用于传送数据)
本文介绍了iOS应用程序中使用的通知机制,包括如何注册、接收和发送通知。详细解释了使用NSNotificationCenter来实现不同组件间的通信,以及如何通过自定义字典对象传递数据。
1万+

被折叠的 条评论
为什么被折叠?



