您的位置:首页 > 移动开发 > IOS开发

【代码笔记】iOS-NSNotificationCenter

2017-06-06 09:14 99 查看
代码:

-(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!!!---------");
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: