【发布时间】:2015-03-31 18:53:25
【问题描述】:
我正在使用https://github.com/obolton/OBMenuBarWindow 创建我的应用程序并面临性能问题。当我通过单击 NSStatusItem 打开我的NSWindow : OBMenuBarWindow 时,没有问题。但是当我再次单击它关闭窗口时,CPU 使用率确实开始快速增加(超过 120%)。再次打开窗口,CPU使用率会正常(0%)。这些每次都会在打开和关闭窗口时发生。我也尝试使用 Instruments 进行调试,但无法解决此问题。我的编码出了什么问题?这是我的代码 sn-p:
@interface MainWindowController : NSWindowController
@property (nonatomic, assign) CGFloat arrowWidth;
@property (nonatomic, assign) CGFloat arrowHeight;
@property (nonatomic) IBOutlet TableController *tableController;
@property IBOutlet OBMenuBarWindow *window;
@end
@implementation MainWindowController
- (void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
self.window.menuBarIcon = [NSImage imageNamed:@"paperclipblack"];
self.window.highlightedMenuBarIcon = [NSImage imageNamed:@"paperclipwhite"];
self.window.title = @"App";
self.window.hasMenuBarIcon = YES;
self.window.attachedToMenuBar = YES;
self.window.isDetachable = YES;
self.arrowWidth = 20;
self.arrowHeight = 10;
}
- (void)setArrowWidth:(CGFloat)width {
self.window.arrowSize = NSMakeSize(width, self.window.arrowSize.height);
}
- (void)setArrowHeight:(CGFloat)height {
self.window.arrowSize = NSMakeSize(self.window.arrowSize.width, height);
}
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (strong) MainWindowController *mainWindowController;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
_mainWindowController = [[MainWindowController alloc] initWithWindowNibName:@"MainWindowController"];
[_mainWindowController showWindow:nil];
}
@end
【问题讨论】:
标签: objective-c cocoa instruments cpu-usage nswindow