2012-02-10 202 views
0

我使用此源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工作正常,工作表出现,但我无法与工作表上的控件(带按钮)进行交互。他们不会对点击产生反应(甚至直观)。

问题出在哪里?

回答

0

嘿,我applicationDidFinishLaunching方法忘记

[newDreamPanel close]; 

。我写了它,因为我想在主窗口启动时不显示面板。

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