UINavigationController未显示根视图控制器 [英] UINavigationController not showing the Root View controller
问题描述
我在视图中有一个大小为320x218的UIView(下面的代码中的menuView)。我想在此视图中加载导航控制器。我使用以下代码来做到这一点:
I have a UIView (menuView in code below) of size 320x218 inside a view. I want to load a navigation controller into this view. Im using the following code to do that:
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];
执行时,根视图不会显示在该视图中。仅显示导航栏,其余视图为空。
When I execute it, the root view is not displayed in that view. Only a navigation bar is displayed and the rest of the view is empty.
修改:
我刚刚在MenuViewController的initWithNibName:和viewDidLoad中放置了一个NSLog()。 initWithNibName中的那个:被调用但viewDidLoad中的那个:不是:S
I just placed an NSLog() in both initWithNibName: and viewDidLoad: of MenuViewController. The one in initWithNibName: gets called but the one in viewDidLoad: doesn't :S
更新:
我试图将 menuController
推送到我的 navigationController
,因为它没有出现,它可能不会在堆栈上。例外:
I tried to push menuController
to my navigationController
thinking since its not appearing, it might not be on the stack. Exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported
推荐答案
我在这里找到答案:
UIViewController -viewDidLoad未被调用
我必须在 -initWithRootViewController
之后添加这些代码行才能加载我的root视图view Controller:
I had to add these lines of code after -initWithRootViewController
in order to load the view of my root view Controller:
navigationController.navigationBarHidden = YES;
[navigationController setView:menuController.view];
这篇关于UINavigationController未显示根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!