iOS关于通知的使用
通知:notification
通知就是三部曲!!!
1.注册通知中心:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(testNotification) name:NOTIFACTION_UPDATE_BIKE_STATE object:nil];
//testNotification为收到通知时调用的方法
2.发送通知:
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFACTION_UPDATE_BIKE_STATE object:nil];
3.销毁通知:(在哪个类里面注册通知中心,就要在哪个类里面销毁)
调用dealloc:方法
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
注意:(1)通知的key一定要匹配好,此处为:NOTIFACTION_UPDATE_BIKE_STATE;
(2)用完就要销毁。