0
我有一些默認的NSViewController。其中我有代碼:如何解決NSViewController/NSView錯誤連接動作與目標?
- (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];
}
該代碼工作它加載視圖取決於該NSUserDefaults。
但是,當嘗試在申報的東西可以說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;
}
現在一切工作正常:
得到了這個。見答案。 – Johnny 2014-10-28 00:58:28