我做了一些示例,通过单击按钮更改视图。
单击视图中的“拳头”按钮时,我不断收到错误消息:
[__NSArrayM changeLogView:]: unrecognized selector sent to instance 0x100539e30
这是简化的代码:
DSWAppDelegate.h
#import <Cocoa/Cocoa.h>
@class DSWHomeViewController;
@interface DSWAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSButton *logBtn;
@property (weak) IBOutlet NSTabView *tabView;
@end
DSWAppDelegate.m
#import "DSWAppDelegate.h"
#import "DSWLogViewController.h"
@implementation DSWAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[self.tabView setTabViewType:NSNoTabsNoBorder];
NSTabViewItem *item = nil;
DSWLogViewController *logvc = [[DSWLogViewController alloc initWithNibName:@"DSWLogViewController" bundle:[NSBundle mainBundle]];
item = [[NSTabViewItem alloc] initWithIdentifier:@"log"];
[item setView:logvc.view];
[self.tabView insertTabViewItem:item atIndex:0];
}
@end
DSWLogViewController.h
#import <Cocoa/Cocoa.h>
@interface DSWLogViewController : NSViewController
@property (weak) IBOutlet NSButton *firstBtn;
@property (weak) IBOutlet NSButton *secondBtn;
@property (weak) IBOutlet NSBox *box;
- (IBAction)changeLogView:(id)sender;
- (IBAction)testSelector:(id)sender;
@end
DSWLogViewController.m
#import "DSWLogViewController.h"
@implementation DSWLogViewController
- (IBAction)changeLogView:(id)sender
{
NSLog(@"changeLogView : %@", sender);
}
- (IBAction)testSelector:(id)sender
{
NSLog(@"testSelector : %@", sender);
}
@end
我检查了文件所有者的类名。