Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone:UINavigationController顶部的怪异空间_Iphone_Objective C_Cocoa Touch_Uinavigationcontroller - Fatal编程技术网

iPhone:UINavigationController顶部的怪异空间

iPhone:UINavigationController顶部的怪异空间,iphone,objective-c,cocoa-touch,uinavigationcontroller,Iphone,Objective C,Cocoa Touch,Uinavigationcontroller,我在iPhone应用程序中添加UINavigationController时遇到了一个奇怪的问题。我添加控制器如下: myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil]; myNavigationViewController *navigationController = [[myNavigationViewController alloc] ini

我在iPhone应用程序中添加UINavigationController时遇到了一个奇怪的问题。我添加控制器如下:

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

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

UIView *finalView = myeNavigationViewController.view;

[self.view addSubview:finalView];
除了在状态栏和UINavigationController标题栏之间的视图顶部有一个奇怪的空白区域外,所有这些似乎都按计划工作。

我在网上搜索过,但不知道该搜索什么。还有其他人有这个问题吗?你能给我指一下需要帮助的方向吗


提前谢谢。

也许你不知怎么搞到了两个UIView, 每个都有一个状态栏。检查xib。

这条线是什么意思

UIView *finalView = myeNavigationViewController.view;
添加到代码中?它是多余的,因为您可以直接添加视图,而无需首先将其分配给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]];

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

查看此问题的答案:


问题是UINavigationController理想情况下应该是UIWindow的直接子视图。它将自行调整位置和大小。在将UINavigationController添加到UIWindow子视图的另一个自定义视图中时,需要考虑状态栏是否显示在UIWindow中,从而确定此自定义视图的位置和大小

我的建议是将自定义视图设置为UINavigationController的子类:

mySubClass_NavigationController*nav=[[mySubClass_NavigationController alloc] initWithRootViewController:viewController ];

[myUIWindow addSubview:nav.view];

在mySubClass_NavigationController中,您可以在自己的身上进行所有定制,无论该控制器是什么

我也为此挣扎了一段时间,使用了与op非常相似的代码,并且在我的导航控制器上方有一个白色条

将UINavigationController添加为UITabController中的视图时出现问题。我的例子中的空间是由UINavigationController的UINavigationBar部分引起的,考虑到状态栏,它实际上是我试图在UINavigationController中显示的视图的重叠部分

这是我在我的一个UITabBarController视图控制器的loadView中得到的代码

SomeUITableViewController *screenList = [[SomeUITableViewController alloc] init];

UINavigationController *navController = [[UINavigationController alloc]
                                         initWithRootViewController:screenList];

CGRect frame = [[navController navigationBar] frame];

frame.origin.y = 0; // Was 20, set to 0 to not take into account the status bar.

[[navController navigationBar] setFrame:frame];

[self setView:[navController view]];

这里有更多的信息

IB中有一个模糊的属性,称为在推送时隐藏底部栏。检查一下。它为我解决了问题