简体   繁体   English

iOS7中表格下方的黑色空白区域,带有嵌套的UIViewControllers

[英]Black empty area below table in iOS7 with nested UIViewControllers

I get some black empty area below a UITableViewController when nested in a certain way (iOS7). 当以某种方式嵌套时(iOS7),我在UITableViewController下得到一些黑色的空白区域。 Would anybody know why that happens? 有人知道为什么会这样吗?

(obviously the code is a 100% stripped down version of the actual app's code) (显然,该代码是实际应用程序代码的100%精简版)


    - (BOOL) application:(UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions {
    UITabBarController *tabBarController = [UITabBarController new];
    UITableViewController *demoViewController = [UITableViewController new];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:demoViewController];

    tabBarController.tabBar.translucent = NO;
    navigationController.navigationBar.translucent = NO;

    // THESE LINES INTRODUCE A BLACK AREA BELOW THE TABLE
    InBetweenViewController *inBetweenViewController = [InBetweenViewController new];
    [inBetweenViewController addChildViewController:navigationController];
    [inBetweenViewController.view addSubview:navigationController.view];
    tabBarController.viewControllers = @[ inBetweenViewController ];

    // INSTEAD, THIS LINE WORKS CORRECTLY
    /* tabBarController.viewControllers = @[ navigationController ]; */

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

@implementation InBetweenViewController
- (void) viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    for (UIView *subview in self.view.subviews) {
        subview.frame = self.view.bounds;
    }
}

@end

It's because your inBetweenViewController doesn't know how to render its childViewController . 这是因为您的inBetweenViewController不知道如何呈现其childViewController You just add the the view of that controller without any further instructions. 您只需添加该控制器的视图即可,无需任何其他说明。 It should be possible to solve this by using a simple autoresizingMask . 应该可以通过使用简单的autoresizingMask解决此autoresizingMask You then also need to make sure that the subview's size is the same as the superview's size when you add it. 然后,在添加子视图时,还需要确保子视图的大小与超级视图的大小相同。 If you need more details on how to do that, let me know. 如果您需要更多有关操作方法的详细信息,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM