NSNotification用法
1.点击发送一个通知。
- (void)menuItemClick:(id)sender;
{
[[NSNotificationCenter defaultCenter] postNotificationName:EVENT_SYSMENU_CLICK object:sender];
}
2.添加通知的监听
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handler_menu_click:)
name:EVENT_SYSMENU_CLICK
object:nil];
3.实现得到通知时调用方法
- (void)handler_menu_click:(NSNotification *)noti;
{
NSLog(@"handler_menu_click %@",noti.object);
}

本文详细介绍了NSNotification在Objective-C中的使用方法,包括如何发送通知、添加监听以及实现回调处理。通过具体的代码示例,读者可以快速掌握NSNotification的基本操作。
775

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



