0

I am trying swapping two Views in a Windows. I am using Cocoa Framework (just for Mac) with Xcode 5.1.1 and NSViewController for get it. All compile perfectly but this doesn't works, I get the next message from compiler:

"libdyld.dylib 0x00007fff866995fd start + 1"

This is my Xcode Project

.h file

#import "Cocoa/Cocoa.h"
#import "PrimaryViewController.h" //My views
#import "SecondViewController.h"

@interface
AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;

@property (weak) IBOutlet NSView *myCustomView;
@property (strong) IBOutlet NSViewController *myViewController;

-(IBAction)button1Clicked:(id)sender;
-(IBAction)button2Clicked:(id)sender;

@end

.m

#import "AppDelegate.h"
@implementation AppDelegate

//@synthesize myCustomView = _myCustomView;<br/>
//@synthesize myViewController = _myViewController;<br/>

-(IBAction)button1Clicked:(id)sender {
    NSLog(@"Clicked on the first button");
    [[_myViewController view ]removeFromSuperview];
    _myViewController = [[PrimaryViewController alloc] initWithNibName:@"PrimaryView­Controller" bundle:nil];
    [_myCustomView addSubview:[_myViewController view]];
    [[_myViewController view] setFrame:[_myCustomView bounds]];
}

-(IBAction)button2Clicked:(id)sender {
    NSLog(@"Clicked on the second button");
    [[_myViewController view] removeFromSuperview];
    _myViewController = [[SecondViewController alloc]initWithNibName:@"SecondaryView­Controller" bundle:nil];
    [_myCustomView addSubview:[_myViewController view]];
    [[_myViewController view]setFrame:[_myCustomView bounds]];
}

@end

Can you help me, please?

modusCell
  • 13,151
  • 9
  • 53
  • 80
Wiilliam
  • 1
  • 1

2 Answers2

0

In SecondaryViewController.xib you named the file owner as SecondViewController. Change it to SecondaryViewController and it should work.

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71
  • I am trying to make the same tutorial workng, but I am unable to do so. I also downloaded the project from the link above, but it crashes, same as the app that I did. Crash message is the following: -[NSNib initWithNibNamed:bundle:] could not load the nibName: NSViewController in bundle NSBundle.....Any idea? – user2417624 Jun 18 '15 at 01:54
0

O yeah, when i created my second "view" i created a file: SecondViewController.xib, SecondViewController.h, and SecondViewController.m

So when i created a instance of it, into the method "button2Clicked" in the, initWithNibName

I called it @"SecondaryViewController" (vs @"SecondViewController").

I removed SecondaryViewController and i changed it, for SecondViewController and all works perfectly, thanks @TheAmateurProgrammerless ;)

Here my project fix it

Wiilliam
  • 1
  • 1