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

iOS下的通知使用

2015-08-28 13:34 295 查看
基础用法和通知的使用不多说,只将自己如何发送通知,同时观察自己的通知,并执行方法。

1.设置通知名,并发送通知。

#define SYAuthorizeResponseCompleted @"authorizeResponseComplete"
NSNotification *notification = [NSNotification notificationWithName:SYAuthorizeResponseCompleted object:self];
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter postNotification:notification];



2.设置监听和移除监听

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self selector:@selector(authorizeCompletle) name:SYAuthorizeResponseCompleted object:nil];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:SYAuthorizeResponseCompleted object:nil];
}


PS:设置监听和移除监听一定要成对存在。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: