我正在尝试在Windows中交换两个视图。我正在使用Cocoa Framework(仅适用于Mac)和Xcode 5.1.1以及NSViewController来获取它。所有编译完美,但这不起作用, 我从编译器得到了下一条消息:
“libdyld.dylib 0x00007fff866995fd start + 1”
.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:@"PrimaryViewController" 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:@"SecondaryViewController" bundle:nil];
[_myCustomView addSubview:[_myViewController view]];
[[_myViewController view]setFrame:[_myCustomView bounds]];
}
@end
请帮帮我吗?
答案 0 :(得分:0)
在SecondaryViewController.xib
中,您将文件所有者命名为SecondViewController
。将其更改为SecondaryViewController
,它应该可以正常工作。
答案 1 :(得分:0)
是的,当我创建第二个“视图”时,我创建了一个文件:SecondViewController.xib
,SecondViewController.h和SecondViewController.m
所以,当我创建它的实例时,在initWithNibName
我称它为“SecondaryViewController”(vs @“SecondViewController”)。
我删除了SecondaryViewController
并更改了SecondViewController
,并且一切正常,感谢@TheAmateurProgrammerless;)