Custom Sheet : can't click buttons

戏子无情 提交于 2019-12-12 02:27:27

问题


I used this source http://www.cats.rwth-aachen.de/library/programming/cocoa

to create my custom sheet.

I created a NSPanel object in existing .xib file and connected with IBOutlet

My source code:

.h

@interface MainDreamer : NSWindow <NSWindowDelegate> 
{    
 ...
 NSPanel *newPanel;
}
...
@property (assign) IBOutlet NSPanel *newPanel;

.m

@dynamic newPanel;
...

//this method is wired with button on main window and calls a sheet
- (IBAction)callPanel:(id)sender
{
    [NSApp beginSheet:newPanel
       modalForWindow:[self window] modalDelegate:self
       didEndSelector:@selector(myPanelDidEnd:returnCode:contextInfo:)
          contextInfo: nil]; //(__bridge void *)[NSNumber numberWithFloat: 0]
}

//this method is wired with cancel and ok buttons on the panel
- (IBAction)endWorkPanel:(id)sender
{
    [newPanel orderOut:self];
    [NSApp endSheet:newPanel returnCode:([sender tag] == 9) ? NSOKButton : NSCancelButton];
} 

//closing a sheet
- (void)myPanelDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
    if (returnCode == NSCancelButton) return;
    else{
        return;
    }
}

So callPanel works fine, sheet appears but I can't interact with controls on the sheet (with buttons). They don't react on a click (even visually).

Where the problem lies?


回答1:


Heh, I forgot about

[newDreamPanel close];

in applicationDidFinishLaunching method. I wrote it because I wanted the panel to not appear when main window launches.

In fact, the Visible At Launch panel's property should be activated in IB. The close method works too, but side effect is that all controls become unable on the panel.



来源:https://stackoverflow.com/questions/9229405/custom-sheet-cant-click-buttons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!