通知的用法
来源:互联网 发布:密码狗复制软件 编辑:程序博客网 时间:2024/06/04 23:18
使用很简单的样子:
首先需要,在需要收听通知的地方注册一个通知
//我向通知中心注册了一条通知“ChangeLabelTextNotification” [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLabelText:) name:@"ChangeLabelTextNotification" object:nil];
注意 方法接收的参数类型是NSNotification
-(void)changeLabelText:(NSNotification *)notification{ id text=notification.object; UILabel *label=(UILabel *)[self.view viewWithTag:102]; label.text=text; }
post通知:
#pragma mark -private-(void)dismiss{ //改变label的值 [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeLabelTextNotification" object:_textField.text]; /*if ([self.delegate respondsToSelector:@selector(changeLabelText:)]) { [self.delegate changeLabelText:_textField.text]; }*/ if ([[UIDevice currentDevice].systemVersion floatValue]<6.0) { //[self dismissModalViewControllerAnimated:YES]; } else { [self dismissViewControllerAnimated:YES completion:^{ }]; }}
当程序退出的时候,通知中心要移除掉:
-(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self name:kChangeLabelTextNotification object:nil]; [super dealloc]; }
0 0
- 通知的用法
- 通知的用法
- 通知的用法
- 通知的用法,传值
- 创建通知-通知的用法
- iOS NSNotification 通知的用法
- 本地通知UILocalNotification的用法
- Android-- Toast通知的用法
- UILocalNotification 本地通知的用法
- iOS 通知的基本用法
- iOS 通知的基本用法
- Notification通知的基本用法
- Notification通知栏的用法
- Notification--------通知的基本用法
- Android中通知的基本用法
- 通知--Notification的功能与用法
- Android通知之Notification的多种用法
- 通知栏的相关用法记录
- 第一个java小程序
- Dreamweaver杀手!Illustrator终结者?Flash的末日?图形图像设计程序之网页版
- linux内核学习之三:linux中的"32位"与"64位"
- FusionCharts封装-dataset和categories
- 快速求幂
- 通知的用法
- "蓝桥杯“基础练习:字母图形
- Java语言与C++语言的差异总结
- contiki tunslip6(SLIP管道文件)
- Android开源框架(一):AndroidAnnotations
- 黑马程序员_02JAVA基础(1)
- LeetCode OJ:Interleaving String
- FLV播放器
- The connection to adb is down, and a severe error has occured.