我正在尝试合并在短时间内发生的NSNotifications。我尝试了以下几点:
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:kMyNotificationName object:self]postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnName forModes:nil];看起来,我的通知被很好地合并了,但是只有在UI交互发生时才会发送它们。例如,我为许多通知排队,但只有当我触摸当前视图控制器的tableView时才会触发它们。如何激发他们,即使没有UI交互?
编辑
我尝试了不同的发布风格: NSPostNow (或NSPostASAP)没有做我需要的事情(我的通知没有合并)
发布于 2013-07-26 09:07:21
见编辑
我没有这个机制的经验(谢谢你让我发现它;),但我想你是在寻找发布风格的NSPostNow。
来自医生们
NSPostNow 通知在合并后立即发布。
所以您的代码可能如下所示:
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:kMyNotificationName object:self] postingStyle:NSPostNow coalesceMask:NSNotificationCoalescingOnName forModes:nil];编辑:在更彻底地阅读文档(特别是NotificationQueues和RunLoopManagement)之后,我认为您的问题是只在默认运行循环模式下发布通知。
根据我的理解和我所做的测试,您应该使用post样式NSPostingASAP (实际上,NSPostingNow相当于在NSNotificationCenter上调用postNotification,这不是您想要的),并为所有常见的运行循环模式(即。NSRunLoopCommonModes).
这将要求队列尽快发布通知,甚至在NSEventTrackingRunLoopMode循环模式(NSRunLoopCommonModes)期间也是如此。
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:kMyNotificationName object:self] postingStyle:NSPostASAP coalesceMask:NSNotificationCoalescingOnName forModes:NSRunLoopCommonModes];https://stackoverflow.com/questions/17876730
复制相似问题