2009-05-18 68 views
2

用NSRect信息發佈通知的最佳方式是什麼?用NSRect信息發佈NSNotification的最佳方法是什麼?

這是我目前的解決方案(使用NSStringFromRect)。

- (void)postNotificationForDirtyRect:(NSRect)rect 
{ 
    NSDictionary *userInfo = 
     [NSDictionary dictionaryWithObject: NSStringFromRect(rect) 
            forKey: ILDirtyRect]; 

    NSNotificationCenter *ncenter = [NSNotificationCenter defaultCenter]; 
    [ncenter postNotificationName: ILDocumentBecomeDirtyRectNotification 
          object: self 
         userInfo: userInfo]; 
} 

但是,我不確定這是否是發送rect結構的最佳方式。

回答

6

您應該使用使用+valueWithRect:類方法創建的NSValue

+0

優秀!謝謝。 – cocoafan 2009-05-18 09:07:36

相關問題