是否有一种易于理解的模式如何发送 NSNotification(目标 C)|通知(Swift 中)以及如何接收通知?代码片段?文档关于这个主题写了大约 150 页。想看一个简单的例子。
发送通知:
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyCacheUpdatedNotification" object:self];
接收:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cacheUpdated:) name:@"MyCacheUpdatedNotification" object:nil];
采取行动:
- (void)cacheUpdated:(NSNotification *)notification {
[self load];
}
并处理它:
[[NSNotificationCenter defaultCenter] removeObserver:self];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)