NSNotification

有时候我们需要程序退出后台或者程序在后台返回前台的时候触发一些事件,这时候我们就可以这样写来触发

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector()name:UIApplicationDidBecomeActiveNotification object:nil];

在selector里面添加要触发的事件就可以了,name就是你需要在什么notification触发这个事件

 

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotificationobject:nil];

而在那个处理事件完成后要加入上面那一句,因为有时候会出现触发两次处理事件,通过这样就可以取消掉了。

posted @ 2013-04-08 17:18  小乐"  阅读(205)  评论(0编辑  收藏  举报