gpt4 book ai didi

ios - 如何从嵌入在容器 View 中的 View Controller 添加导航项

转载 作者:技术小花猫 更新时间:2023-10-29 10:35:19 25 4
gpt4 key购买 nike

我有一个带有容器 View 的 VC(导航 Controller 的根 VC)。容器 View 嵌入另一个 VC。我相信这使得后者成为前者的子 VC。我想从子 VC 的代码向导航栏添加一个按钮。我试过使用 parentviewcontoller,但它不起作用:

UIBarButtonItem *newConvoButton = [[UIBarButtonItem alloc] initWithTitle:@"New convo" style:UIBarButtonItemStyleBordered target:self action:@selector(newConvoInit:)];
self.parentViewController.navigationItem.rightBarButtonItem = newConvoButton;

而且我知道如果代码在父 VC 中并且我删除了“.parentViewController”,代码会正常工作。

那么如何从嵌入式 VC 添加导航项呢?

编辑:

截图如下: 1self.parentViewController 右侧日志(null)上的 TVC。

最佳答案

rdelmar 在这里提供了答案:interact the navigation controller bar button with embed container view

在 viewWillAppear 之前无法访问父级

关于ios - 如何从嵌入在容器 View 中的 View Controller 添加导航项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17175915/

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