Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何解决将操作与目标连接时出现的NSViewController/NSView错误?_Objective C_Xcode_Cocoa - Fatal编程技术网

Objective c 如何解决将操作与目标连接时出现的NSViewController/NSView错误?

Objective c 如何解决将操作与目标连接时出现的NSViewController/NSView错误?,objective-c,xcode,cocoa,Objective C,Xcode,Cocoa,我有一些默认的NSViewController。其中我有代码: - (void)viewDidLoad { // Do view setup here. NSUserDefaults *defaults = [[NSUserDefaults alloc] init]; if(![defaults boolForKey:@"isLoggedIn"]){ NSLog(@"Not logged in... Loading settings");

我有一些默认的NSViewController。其中我有代码:

- (void)viewDidLoad {

    // Do view setup here.

    NSUserDefaults *defaults = [[NSUserDefaults alloc] init];

    if(![defaults boolForKey:@"isLoggedIn"]){


        NSLog(@"Not logged in... Loading settings");

        NSViewController *settings = [[NSViewController alloc] initWithNibName:@"Settings" bundle:nil];
        [self.view addSubview:settings.view];

    }
    else{
        NSLog(@"Logged in... Loading inbox");
        NSViewController *inbox = [[NSViewController alloc] initWithNibName:@"Inbox" bundle:nil];

        [self.view addSubview:inbox.view];
    }
    [super viewDidLoad];
}
加载视图时代码是否工作取决于默认值

但是当我尝试在Inbox.m/Inbox.h中声明某个内容时,我会遇到以下错误:

Could not connect the action testView: to target of class NSViewController
在Inbox.m中,我有:

- (void)viewDidLoad {
    NSLog(@"Inbox loaded.");

    [super viewDidLoad];
    // Do view setup here.
}
并且从不执行NSLog。我想有几个NIB和不同的NSViewController连接到它

我猜我添加子视图的方式不对。这就好像视觉元素就在那里,没有其他东西。

我通过以下方法来解决这个问题:

    Inbox *inbox = [[Inbox alloc] initWithNibName:@"Inbox" bundle:nil];
    _viewController = inbox;

    //Where _viewController is 
    NSViewController *_viewController; 

    //defined in 
   @interface Default : NSViewController{
       NSViewController *_viewController; 
   }

现在一切正常。

收到了。见答案。