0

我正在尝试在 Windows 中交换两个视图。我正在使用带有 Xcode 5.1.1 和 NSViewController 的 Cocoa Framework(仅适用于 Mac)来获取它。全部编译完美,但这不起作用,我从编译器收到下一条消息:

“libdyld.dylib 0x00007fff866995fd 开始 + 1”

这是我的 Xcode 项目

.h 文件

#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

你能帮我吗?

4

2 回答 2

0

SecondaryViewController.xib您将文件所有者命名为SecondViewController. 将其更改为SecondaryViewController,它应该可以工作。

于 2014-08-02T13:03:26.897 回答
0

哦,是的,当我创建第二个“视图”时,我创建了一个文件:SecondViewController.xib、SecondViewController.h 和 SecondViewController.m

所以当我创建它的一个实例时,进入方法“button2Clicked”中,initWithNibName

我称它为@“SecondViewController”(相对于@“SecondViewController”)。

我删除SecondaryViewController并更改了它,因为SecondViewController所有工作都完美无缺,感谢@TheAmateurProgrammerless ;)

在这里我的项目修复它

于 2014-08-02T15:12:52.947 回答