我正在尝试在Windows中交换两个视图。我使用Cocoa (仅用于Mac)和Xcode 5.1.1以及NSViewController来获取它。所有的编译都很完美,但这不起作用,我从编译器那里得到了下一条消息:
Libdyld.dylib 0x00007fff866995fd start +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:@"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你能帮帮我吗?
发布于 2014-08-02 13:03:26
在SecondaryViewController.xib中,您将文件所有者命名为SecondViewController。将其更改为SecondaryViewController,它应该可以工作。
发布于 2014-08-02 15:12:52
是的,当我创建第二个“视图”时,我创建了一个文件:SecondViewController.xib、SecdViewController.h和SecdViewController.m。
因此,当我创建它的一个实例时,在initWithNibName中的“initWithNibName”方法中
我把它叫做“SecondaryViewController”(vs @"SecondViewController")。
我删除了SecondaryViewController并修改了它,因为SecondViewController和所有的功能都很完美,谢谢@TheAmateurProgrammerless ;)
https://stackoverflow.com/questions/25092272
复制相似问题