我点击位于我的OS X应用程序主窗口的NSButton (openPane,使用以下方法显示一个NSPanel (myPanel):
- (IBAction)openPanel:(id)sender {
[_myPanel makeKeyAndOrderFront:nil];
}除了我第一次单击该按钮(OpenPanel)时在调试区域得到以下描述外,一切都按预期进行:
"unlockFocus called too many times. Called on NSButton: 0x610000141080."面板的属性选择如下:
Style: Utility Panel,
Appearance:Title Bar and Shadow,
Controls: Close,
Behaviour: Restorable,
Memory: Deferred我浏览了网页,但找不到任何解释。有谁知道为什么会发生这种情况,或者如何解决它?
发布于 2015-09-02 06:10:56
我使用XCode 7.0 beta 6使用故事板和段来显示工作表时也遇到了同样的问题。这似乎是一些常见的问题,如果您直接从操作打开面板。
要解决这个问题,只需从主队列中打开面板:
- (IBAction)openPanel:(id)sender {
dispatch_async(dispatch_get_main_queue(), ^{
[_myPanel makeKeyAndOrderFront:nil];
});
}这也将解决来自swift和storyboards的类似问题。使用此快速代码调用segue:
@IBAction func onButtonClicked(sender: AnyObject) {
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("identifier", sender: self);
})
}发布于 2014-12-30 18:57:14
不确定那里发生了什么,但我会尝试这样显示您的NSPanel:
-(IBAction)openPanel:(id)sender {
[[NSApplication sharedApplication] beginSheet:_myPanel
modalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];此外,您还应确保已为您的NSPanel激活了Release When Closed复选框。在Interface Builder中搜索它。
编辑:你是不是在你的NSPanel上画了什么?设置NSColor还是显示NSImage?我的猜测是,您正在显示一个NSImage,并弄乱了一些与此相关的东西:Apple Doc: lockFocus
发布于 2015-01-31 07:38:37
我用下面的代码修复了同样的问题
标头中的
@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将清理面板。
https://stackoverflow.com/questions/27703929
复制相似问题