通知
1.建立通知中心
NSNotificationCenter *center = [NSNotificationCenterdefaultCenter];
2.利用通知中心发通知
2.1创建一个通知对象
NSNotification *note = [NSNotificationnotificationWithName:@"tech_new"object:tx];
2.2利用通知中心,将这则通知发出去
[center postNotification:note];
3.监听通知中心发出的通知
[center addObserver:p selector:@selector(gotNews)name:@"tech_new" object:tx];
4.创建通知对象的时候可以带上一个属性useinfo ----->是这则通知的详情
NSNotification *note = [NSNotificationnotificationWithName:@"tech_new"object:txuserInfo:@{
@"title" : @"今天天气真好",
@"source" : @"腾讯网"
}];
5.通知不要重复添加。
6.移除通知 (arc不用移除)
[ceter remove:p];
[ceter remove:p name:@"tech_news" object:tx];
本文详细介绍了如何在iOS应用中使用NSNotification来创建、发布和监听通知,包括通知对象的创建、信息携带、重复添加的注意事项以及通知移除的方法。
188

被折叠的 条评论
为什么被折叠?



