有没有一种易于理解的模式来发送 NSNotification( objective-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];
关于iphone - 如何发布和接收 NSNotifications( objective-c ) |通知(Swift 中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2676398/