0
我搜索了并且找不到与我的类似的问题。无法将操作btnPressed连接到类NSViewController的目标
我有一个父视图(AppDelegate)和一个NSButton的子视图(NSViewController)。
在我父视图(AppDelegate中),我使用IB添加一个CustomView和NSViewController在MainMenu.xib和使用下面的代码到视图更改为儿童
AppDelegate.h -
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@end
AppDelegate.m -
#import "AppDelegate.h"
#import "Child.h"
@interface AppDelegate()
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSView *myCustomView;
@property (weak) IBOutlet NSViewController *myViewController;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
Child *childView = [[Child alloc] init];
[[self.myViewController view] removeFromSuperview];
self.myViewController = [childView initWithNibName:@"Child" bundle:nil];
[self.myCustomView addSubview:[self.myViewController view]];
[[self.myViewController view]setFrame:[self.myCustomView bounds]];
}
这里是儿童(NSViewController ),我使用IB来添加一个按钮并将其与我的孩子链接。
Child.h -
#import <Cocoa/Cocoa.h>
@interface Child : NSViewController
@end
Child.m -
#import "Child.h"
@interface Child()
@end
@implementation Child
- (IBAction)btnPressed:(id)sender {
}
@end
问题是没有编译错误,但是当我运行它。它显示
2014-10-09 22:51:43.952 Test[1439:303] Could not connect the action btnPressed: to target of class NSViewController
孩子可以赶上按钮的新闻事件。在我看来,Xcode抱怨按钮操作未与父视图(AppDelegate)链接。
我该如何摆脱这个警告? Apple是否允许带有此类警告的OSX应用程序?
您是否将按钮连接到您的操作方法? – 2014-10-09 23:11:54
是的,我做到了。这就是为什么当我点击按钮时btnPressed被调用。应用程序本身运行良好。我只是不知道如何摆脱这个信息。我想在这里上传项目,但我不知道如何。 – yohon 2014-10-10 08:24:19
重现它非常简单。 – yohon 2014-10-10 08:47:05