iPhone:UINavigationController顶部的奇怪空间

and*_*com 13 iphone cocoa-touch objective-c uinavigationcontroller

我在向iPhone应用程序添加UINavigationController时遇到了一个奇怪的问题.我按如下方式添加控制器:

myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil];

myNavigationViewController *navigationController = [[myNavigationViewController alloc] initWithRootViewController:viewController];

UIView *finalView = myeNavigationViewController.view;

[self.view addSubview:finalView];
Run Code Online (Sandbox Code Playgroud)

所有似乎都按计划工作,除了我在状态栏和UINavigationController标题栏之间的视图顶部有一个奇怪的空白区域. alt text http://www.andrewskinner.name/problem.png

我在网上搜索过但不知道该搜索什么.有没有其他人有这个问题?你能指点我一些帮助的方向吗?

提前致谢.

Cra*_*aig 11

什么行

UIView *finalView = myeNavigationViewController.view;
Run Code Online (Sandbox Code Playgroud)

添加到代码?它是多余的,因为你可以直接添加视图而不首先将它分配给UIView - 加上它是不正确的,因为它引用了myNavigationController而不是navigationController ..
我倾向于这样做

myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil];    
myNavigationViewController *navigationController = [[myNavigationViewController alloc] initWithRootViewController:viewController];
[navigationController.view setFrame: [self.view bounds]];
navigationController.delegate = self;
[self.view addSubview:[navigationController view]];
Run Code Online (Sandbox Code Playgroud)

将框架设置为边界也会删除您询问的顶部的空白区域.