我使用以下方法点击位于我的OS X应用程序主窗口的NSButton (openPane
l)以显示NSPanel (myPanel
):
- (IBAction)openPanel:(id)sender {
[_myPanel makeKeyAndOrderFront:nil];
}
一切都按预期工作,除了我第一次单击按钮(openPanel)时在调试区域中得到以下描述:
"unlockFocus called too many times. Called on NSButton: 0x610000141080."
Panel的属性选择如下:
Style: Utility Panel,
Appearance:Title Bar and Shadow,
Controls: Close,
Behaviour: Restorable,
Memory: Deferred
我查看了网页但找不到任何解释。有谁知道为什么会这样或者如何解决它?
答案 0 :(得分:1)
I had the same problem using XCode 7.0 beta 6 using storyboards and a segue to display a sheet. It seems some common problem which happens if you open the panel directly from the action.
To solve the problem, just open the panel from the main queue:
- (IBAction)openPanel:(id)sender {
dispatch_async(dispatch_get_main_queue(), ^{
[_myPanel makeKeyAndOrderFront:nil];
});
}
This will also solve similar problems from swift and storyboards. Use this swift code to call a segue:
@IBAction func onButtonClicked(sender: AnyObject) {
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("identifier", sender: self);
})
}
答案 1 :(得分:0)
不确定那里发生了什么,但我会尝试这个来展示你的NSPanel:
-(IBAction)openPanel:(id)sender {
[[NSApplication sharedApplication] beginSheet:_myPanel
modalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
此外,您应确保为您的NSPanel激活关闭后释放复选框。 在Interface Builder中搜索它。
编辑:你在NSPanel上画画了吗?设置NSColor或显示NSImage? 我的猜测是你正在显示一个NSImage并且搞砸了一些事情:Apple Doc: lockFocus
答案 2 :(得分:0)
我已修复了以下
的相同问题在标题中
@interface aWindowController : NSWindowController
{
/* other Vars */
NSOpenPanel *panel;
}
在.m
- (void)windowDidLoad {
[super windowDidLoad];
/* other stuff */
/* set Panel Properties */
panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
[panel setAllowsMultipleSelection:YES];
}
NSButton IBACTION中的
- (IBAction)getFiles:(id)sender
{
NSArray *resultArry;
if([panel runModal] == NSFileHandlingPanelOKButton ){
resultArry = [panel URLs];
return resultArry;
}
return nil;
}
ARC将清理面板。
答案 3 :(得分:0)
我遇到了一个叫做Segue的NSPopUpButton同样的问题,而@Flovdis的答案对我有用。
这是我使用的Objective C代码:
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"MySegue" sender:self];
});