无法连接到可可的动作“按钮”?

时间:2015-06-02 07:24:09

标签: objective-c xcode macos

我是可可应用程序开发的新手。我正在尝试在可可中创建基于模型的应用程序。

我在cocoa应用程序中创建了两个窗口,例如mainMenu.xib和windows2.xib。在创建项目和手动创建windows2.xib时创建mainMenu.xib。现在我在mainMenu.xib上插入一个按钮说(button1),当点击按钮然后window2.xib加速但当点击第二个窗口的按钮时会产生错误。代码正在进行中

AppDelegate.h

@interface AppDelegate : NSObject <NSApplicationDelegate>

和AppDelegate.mm

#import "AppDelegate.h"

@implementation AppDelegate
  NSWindowController *AdvSettingController;
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {

// Insert code here to initialize your application
}

- (IBAction)AdvSettingBtn:(id)sender {

AdvSettingController= [[NSWindowController alloc] initWithWindowNibName:@"window2"];

[NSApp runModalForWindow:AdvSettingController.window];
[NSApp endSheet:AdvSettingController.window];
[AdvSettingController.window orderOut:self];
}

- (IBAction)OkBtn:(id)sender {
 [NSApp terminate:self];
}

- (IBAction)CancelBtn:(id)sender {
    [NSApp terminate:self];
    }

现在,windows2.h文件用于第二个窗口(windows2.xib)

#import <Cocoa/Cocoa.h>

@interface windows2 : NSWindowController
@end    

和windows2.mm

#import "windows2.h"

@interface windows2 ()

@end

@implementation windows2

 - (id)initWithWindow:(NSWindow *)window
{


self = [super initWithWindowNibName:@"windows2"];
if (self) {     
// Initialization code here.


 }

return self;

}

- (void)windowDidLoad
{
    [super windowDidLoad];

    // Implement this method to handle any initialization after your window controller's window has been loaded from 
}
- (IBAction)CancelBtn:(id)sender { 
   [self.window close];
} **//Error is generating at run time when clicked on button of second dialog**

1 个答案:

答案 0 :(得分:1)

您正在尝试连接CancelButton方法,但实例方法名为CancelBtn