开发者

Cocoa - Adding a Navigation Controller to a subview

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 tie开发者_如何学God 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?


You have your two view controllers reversed. Try something like this:

self.MainView = [[MainViewController alloc] initWithNibName:@"MainView" bundle:[NSBundle mainBundle]];

UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:MainView];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜