Cocoa - 将导航控制器添加到子视图
我目前正在为 iPad 开发一个基于视图的应用程序,该应用程序的主页上有 3 个独立的视图。顶部有一个自定义菜单,侧面有一个状态列表,还有一个主视图。我在主视图中遇到的问题是尝试添加导航控制器。
在 AppPadViewController.h
@interface AppPadViewController.h : UIViewController {
MainViewController *MainView;
}
@property (nonatomic,retain) IBOutlet MainViewController *MainView;
和 AppPadViewController.m
@synthesize MainView;
- (void) viewDidLoad {
[super viewDidLoad];
MainView.navigationItem.title = @"Home";
UINavigationController *mainNavController = [[UINavigationController alloc] initWithNibName:@"MainView" bundle:[NSBundle mainBundle]];
self.MainView = [MainViewController alloc] initWithRootViewController:mainNavController];
}
中,在笔尖中,我添加了我想要的视图,并将其绑定到 MainView,然后添加 MainViewController 并将其绑定到文件所有者和视图。
当我运行此命令时,我在 initWithRootViewController 行上抛出“无法识别的选择器”错误。
任何人都可以看到代码有任何问题,或者建议更好的方法将导航控制器添加到子视图吗?
I'm currently working on a view based app for the iPad that has 3 seperate views on the main page. A custom menu up the top, a status list on the side, and a main view. The issue I am having with the main view is trying to add a navigation controller.
In AppPadViewController.h
@interface AppPadViewController.h : UIViewController {
MainViewController *MainView;
}
@property (nonatomic,retain) IBOutlet MainViewController *MainView;
And in AppPadViewController.m
@synthesize MainView;
- (void) viewDidLoad {
[super viewDidLoad];
MainView.navigationItem.title = @"Home";
UINavigationController *mainNavController = [[UINavigationController alloc] initWithNibName:@"MainView" bundle:[NSBundle mainBundle]];
self.MainView = [MainViewController alloc] initWithRootViewController:mainNavController];
}
And in the nib I have added the view where I would like it, and tied it in to the MainView, and then added the MainViewController and tied it to the File Owner and view.
When I run this, I get an 'Unrecognized Selector" error thrown on the initWithRootViewController line.
Can anyone see any problem with the code, or suggest a better way to add a navigation controller to a sub view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的两个视图控制器颠倒了。尝试这样的事情:
You have your two view controllers reversed. Try something like this: