iOS下的通知使用
2015-08-28 13:34
295 查看
基础用法和通知的使用不多说,只将自己如何发送通知,同时观察自己的通知,并执行方法。
1.设置通知名,并发送通知。
2.设置监听和移除监听
PS:设置监听和移除监听一定要成对存在。
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:设置监听和移除监听一定要成对存在。
相关文章推荐
- ios开发之 苹果审核被拒,使用第三方登录,但手机没有安装客户端的平台
- iOS开发之 二维码生成/二维码扫描
- ios开发之 icon规范+启动图规范+欢迎页规范
- ios开发之常用的NSLOG日志打印格式
- SVN (TortioseSVN) 版本控制之忽略路径(如bin、obj、gen)
- IOS-Svn-Cornerstone
- ios 常用的打印输出方法
- iOS沙盒(sandbox)
- iOS学习之CoreData的增删改查
- IOS: 应用截图尺寸和启动图片
- 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记43 保护NSNotification的内存安全
- iOS设计模式 - 单例
- 仿煎蛋iOS项目的准备(0)
- iOS开发之多图片无缝滚动组件封装与使用
- iOS学习 - scrollView(图片轮播器)
- ios下元素溢出设置 overflow:auto; 不能滑动解决办法
- iOS开发本地缓存(数据离线缓存、读取、释放)
- iOS Xcode6.4添加pch文件
- iOS随笔记-开发中遇到的#import头文件找不到的问题解决办法
- iOS AutoLayout自动布局中级开发教程(9)-VisualFormat可视化格式字符串构成