【问题标题】:Custom Sheet : can't click buttons自定义工作表:无法单击按钮
【发布时间】:2012-02-10 14:35:30
【问题描述】:

我使用了这个来源http://www.cats.rwth-aachen.de/library/programming/cocoa

创建我的自定义工作表。

我在现有的 .xib 文件中创建了一个NSPanel 对象并与IBOutlet 连接

我的源代码:

.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;
    }
}

所以callPanel 工作正常,工作表出现,但我无法与工作表上的控件交互(带有按钮)。他们不会对点击做出反应(甚至在视觉上)。

问题出在哪里?

【问题讨论】:

    标签: cocoa nspanel


    【解决方案1】:

    呵呵,我忘了

    [newDreamPanel close];
    

    applicationDidFinishLaunching 方法中。我写它是因为我希望面板在主窗口启动时不出现。

    实际上,Visible At Launch 面板的属性应该在 IB 中激活。 close 方法也可以,但副作用是面板上的所有控件都无法使用。

    【讨论】:

      猜你喜欢
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多