Reputation: 54
I click on a NSButton (openPane
l) which is located on the main window of my OS X app to show a NSPanel (myPanel
) using the following method:
- (IBAction)openPanel:(id)sender {
[_myPanel makeKeyAndOrderFront:nil];
}
Everything works as expected except I get the following description in the debug area only the first time I click on the button (openPanel):
"unlockFocus called too many times. Called on NSButton: 0x610000141080."
The attributes of the Panel are selected as follows:
Style: Utility Panel,
Appearance:Title Bar and Shadow,
Controls: Close,
Behaviour: Restorable,
Memory: Deferred
I have looked through the web but can not find any explanation. Does anyone know why this happens or how to resolve it?
Upvotes: 0
Views: 2139
Reputation: 23
I had the same problem with a NSPopUpButton that called a Segue and @Flovdis answer worked for me.
This is the Objective C code I used:
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"MySegue" sender:self];
});
Upvotes: 0
Reputation: 3095
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);
})
}
Upvotes: 1
Reputation: 1
I have fixed the same problem with the following
In Header
@interface aWindowController : NSWindowController
{
/* other Vars */
NSOpenPanel *panel;
}
In .m
- (void)windowDidLoad {
[super windowDidLoad];
/* other stuff */
/* set Panel Properties */
panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
[panel setAllowsMultipleSelection:YES];
}
in NSButton IBACTION
- (IBAction)getFiles:(id)sender
{
NSArray *resultArry;
if([panel runModal] == NSFileHandlingPanelOKButton ){
resultArry = [panel URLs];
return resultArry;
}
return nil;
}
ARC will clean up the panel.
Upvotes: 0
Reputation: 7391
Not sure what is going on there but I would try this to show your NSPanel:
-(IBAction)openPanel:(id)sender {
[[NSApplication sharedApplication] beginSheet:_myPanel
modalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
Also you should make sure that Release When Closed checkbox is activated for your NSPanel. Search for it in the Interface Builder.
EDIT: Are you drawing something on your NSPanel ? Setting a NSColor or showing a NSImage ? My guess is that you are displaying a NSImage and messed something up concerning this: Apple Doc: lockFocus
Upvotes: 0