0

我做了一些示例,通过单击按钮更改视图。

单击视图中的“拳头”按钮时,我不断收到错误消息:

[__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

我检查了文件所有者的类名。

文件所有者

4

1 回答 1

0

changeLogView:有些东西正在向可变数组而不是您的视图控制器发送消息。很可能,无论您连接IBAction到什么都指向错误的对象 - 某种数组,而不是您的视图控制器。

于 2013-07-12T12:03:22.630 回答