NSNotificationQueue를 사용하여 병합을 수행하는 다음 코드를 작성했습니다. 이벤트가 여러 번 발생하더라도 하나의 알림 만 게시하고 싶습니다.NSNotificationQueue를 사용하는 동안 병합
- (void) test000AsyncTesting
{
[NSRunLoop currentRunLoop];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(async000:) name:@"async000" object:self];
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:@"async000" object:self]
postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnName forModes:nil];
while (i<2)
{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
NSLog(@"Polling...");
i++;
}
}
- (void) async000:(NSNotification*)notification;
{
NSLog(@"NSNotificationQueue");
}
'test000AsyncTesting'메서드를 호출 할 때마다 동일한 이름의 알림이 대기열에 추가됩니다. 통합의 개념에 따라 대기열에 여러 개의 알림이 있지만 이름이 같은 경우에는 한 번만 게시됩니다. 그러나 코드를 실행하면 'async000 :'이 NSNotificationQueue에 추가 된 알림 수와 정확히 동일한 여러 번 호출됩니다. 병합이 작동하지 않는다고 생각합니다. 나를 위해
은, 코드의 실행은 두 경우 모두 동일하게 유지 :
사례 1 : [[NSNotificationQueue defaultQueue] enqueueNotification : [NSNotification notificationWithName : @ "async000"개체 : 자기] postingStyle : NSPostWhenIdle coalesceMask : NSNotificationCoalescingOnName forModes : nil];
케이스 2 : [NSNotificationQueue defaultQueue] enqueueNotification : [NSNotification notificationWithName @ "async000"개체 : 자기] postingStyle : NSPostWhenIdle];
제 코드에서 오류를 알려주십시오.
시계, 당신은 항상'super' 내부''에 dealloc' 호출해야합니다 - (무효)의 dealloc을;' – Daniel