正如您在屏幕截图中看到的那样,这里是灰色UIView
的,我将其用作容器。在代码中,我分配了一个UINavigationController
并将它的视图作为子视图添加到灰色容器视图中。有(您可以UINavigationController
在RootViewController
左侧看到截断的表格视图 - 它是我的 UINavigationController 的根视图控制器)。
我的问题是如何将所有方面都固定到超级视图边界。因为现在我只能看到RootViewController
视图的一部分。
在情节提要中,我已将所有约束设置为灰色容器视图RootViewController
和UINavigationController
. 如果我通常PushViewController
不是添加为子视图,它会显示而不会出现中断问题。
这是我的代码UIViewController
,其中包含灰色容器视图:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
KNCouponsViewController *couponsViewControllerByList = [KNInstantiateHelper instantiateViewControllerWithIdentifier:@"KNCouponsViewController"];
self.theNavigationController = [[UINavigationController alloc] initWithRootViewController:couponsViewControllerByList];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.theContainerView addSubview:self.theNavigationController.view];
}
这是灰色容器视图的约束
这是已切断表的根视图控制器的视图的约束:
似乎一个简单的解决方案是将UINavigationController
视图设置为与灰色容器相同的宽度和高度:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect rect = self.theContainerView.frame;
rect.origin.x = 0;
rect.origin.y = 0;
[self.theNavigationController.view setFrame:rect];
[self.theContainerView addSubview:self.theNavigationController.view];
}
然后它工作正常。但我认为,如果我们不只修改框架,它会起作用吗?