NSNotificationCenter以及app的几种运行状态

来源:互联网 发布:mac 如何编写html 编辑:程序博客网 时间:2024/06/05 20:02

1~NSNotificationCenter(必须先注册,再发送)

注册通知:即要在什么地方接受消息

           [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(mytest:) name:@" mytest" object:nil]

           [[NSNotificationCenter defaultCenter] postNotificationName:@"mytest" object:searchFriendArray];

   object:传递的参数

- (void) mytest:(NSNotification*) notification

{

   id obj = [notification object];//获取到传递的对象

2~移除某个通知

    [[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardWillShowNotificationobject:nil];


3~APP几种运行状态
[[NSNotificationCenterdefaultCenter]addObserver:self selector:@selector(clearMemory)
  name:UIApplicationDidReceiveMemoryWarningNotification object:nil];//内存警告

[[NSNotificationCenterdefaultCenter]addObserver:self selector:@selector(cleanDisk)  name:UIApplicationWillTerminateNotification object:nil];//APP运行结束

[[NSNotificationCenterdefaultCenter]addObserver:self selector:@selector(backgroundCleanDisk) name:UIApplicationDidEnterBackgroundNotification

 object:nil];//退到后台



0 0
原创粉丝点击