我在 View 中有一个大小为 320x218 的 UIView(下面代码中的 menuView)。我想将导航 Controller 加载到该 View 中。我使用以下代码来执行此操作:
MenuViewController *menuController = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:menuController];
navigationController.navigationBarHidden = YES;
[menuView addSubview:navigationController.view];
[menuController release];
[navigationController release];
当我执行它时, Root View 不会显示在该 View 中。仅显示导航栏, View 的其余部分为空。
编辑:
我刚刚在 MenuViewController 的 initWithNibName: 和 viewDidLoad: 中放置了一个 NSLog() 。 initWithNibName: 中的那个被调用,但 viewDidLoad: 中的那个没有被调用:S
更新:
我尝试将 menuController
推送到我的 navigationController
,因为它没有出现,它可能不在堆栈上。异常(exception):
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported
最佳答案
调用layoutsubviews确实有效。
[super loadView];
[self.view addSubview:navigationController.view];
[navigationController.view layoutSubviews];
关于iphone - UINavigationController 不显示 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6909660/