开发者

Refresh NSView content when the view is displayed with MAAttachedWindow

开发者 https://www.devze.com 2023-02-07 23:01 出处:网络
Im my application, I display a NSView when a user click on an icon in the systemstatusbar. This NSView is displayed with MAAttachedWindow.

Im my application, I display a NSView when a user click on an icon in the systemstatusbar. This NSView is displayed with MAAttachedWindow.

开发者_开发知识库

My question is : how to refresh the NSView content when the attachedWindow is displayed (makeKeyandorderFront)

I've tried to refresh the content in the awakeFromNib method,but it works only once.

Could anyone help me?

thanks


The solution I've found:

I've added a observer in my view: I've set the object to [selft window] to listen the NSWindowDidBecomeKeyNotification notification of the MAAttachedwindow.

-(void)awakeFromNib

{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:[self window]];

}

-(void) windowDidBecomeKey:(NSNotification *)note

{

// Do refresh here

}


The reason -awakeFromNib only works once is presumably because you're only loading the assembly from the xib once and keeping it around.

Presumably whatever action actually shows your view in the MAAttachedWindow instance is the ideal place to "refresh" it before display, ie your own call to -makeKeyAndOrderFront:.

So: What have you tried?

0

精彩评论

暂无评论...
验证码 换一张
取 消