gpt4 book ai didi

ios - 在导航 Controller 中添加一次公共(public) View

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:07 30 4
gpt4 key购买 nike

我想要实现的是在界面生成器中设计 UI 的“共享”部分,并使用 subview Controller 向用户显示内容。这听起来像是在尝试重新发明 UINavigationController,但事实并非如此。事实上,整个事情都嵌入了一个。

看起来像这样: example view

现在,我要做的是更改此 BaseViewController 的 subview Controller ,并在导航栏中指示此更改,以便保留其所有功能。

我尝试添加这样的方法:

+ (UIViewController *)baseViewControllerWithChild:(UIViewController *)child {
BaseViewController *base = [BaseViewController new];
[base addChildViewController:child];
child.view.frame = base.childViewControllerContainer.frame;
[base.view addSubview:child.view];
[child didMoveToParentViewController:base];

return base;
}

然后像这样使用它:

- (void)didTouch:(UIButton *)sender { 
[self.parentViewController.navigationController pushViewController:[BaseViewController baseViewControllerWithChild:[DummyViewController new]] animated:YES];
}

(注意:DummyViewController 正是 - 一个虚拟 vc,仅用于测试,它仅在 viewDidLoad 中设置了背景颜色)

此方法是第一个 subview Controller 中按钮的处理程序。到目前为止,一切都很好。不幸的是,结果并不如预期——推送的 View Controller 是黑色的。起初我认为这是因为 BaseViewController 是在 storyboard 中设计的,并且最初设置为导航 Controller 的 rootViewController。将它移动到 xib 文件并从代码设置对我来说不太有效,因为您不能在 xib 中添加 Container View

总而言之,我希望有一个由 BaseViewController 类管理的基础设计,内容将作为它的 childViewController 添加。推送新的 View Controller 将是对这些 childViewController 执行操作的结果,并且应该相应地更新导航堆栈。

此外,整个系统需要与 iOS 7 兼容。

非常感谢任何关于如何尝试实现这一目标的帮助!

最佳答案

问题是由 base.childViewControllerContainernil 引起的 - 这是由于 View Controller 的 view 属性被延迟加载引起的.在访问 base.childViewControllerContainer 之前添加 [base view] 解决了这个问题,但我不确定这是否是唯一、最好的方法。

关于ios - 在导航 Controller 中添加一次公共(public) View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34453197/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com