通知传值[NSNotificationCenter defaultCenter]

今天遇到通知传值,拿出之前的demo又翻了翻,还是决定把它写成博客.
通知传值有四个步骤:
1  前一个界面添加观察者.注册通知.
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(reloadValue:) name:@"asdf"object:nil];
2   后面的某个界面,传值
[[NSNotificationCenter defaultCenter] postNotificationName:@"asdf" object:_TextField.text];
3   实现通知中心的方法赋值.
- (void)reloadValue:(NSNotification *)sender
{
    id text = sender.object;
    _label.text = text;
}
4   使用完dealloc要释放通知.
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"asdf" object:nil];
//释放该方法的时候写在dealloc里,ARC下不用写[super dealloc].

 亲们,虽说通知可以随意传值,可是一定要,首先条件,一定要先注册通知.所以通知一般用于,从后往前传值.

原文地址:https://www.cnblogs.com/xclidongbo/p/4096298.html