【代码笔记】iOS-NSNotificationCenter

代码:

【代码笔记】iOS-NSNotificationCenter
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated]; //移除通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"flag" object:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //注册通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(setMessages) name:@"flag" object:nil];
} -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//执行通知的操作
[[NSNotificationCenter defaultCenter]postNotificationName:@"flag" object:nil]; }
//通知所执行的操作
-(void)setMessages
{
NSLog(@"---------I--love---you!!!---------");
}
【代码笔记】iOS-NSNotificationCenter
上一篇:spring之依赖注入


下一篇:Java程序打开指定地址网页