swift - 混合程序化和故事板。按钮单击不会在导航控制器中打开下一个 VC
问题描述
我有一个以编程方式构建的标签栏控制器。它看起来像这样:
类NewTabBarController:UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
createTabbar()
}
func createTabbar() {
let deliveryViewController = storyBoard.instantiateViewController(identifier: "DeliveryViewController") as? DeliveryViewController
deliveryViewController?.tabBarItem.image = #imageLiteral(resourceName: "icon_deliver")
deliveryViewController?.title = "Delivery"
planDictionary["planType"] = Constants.Mealplan.deliveryPlan
deliveryViewController?.planDictionary = planDictionary
// Excluded other tabs and view controller creations since they are the same
}
现在这个 DeliveryViewController 在故事板中创建并嵌入到导航控制器中
它有一个按钮点击动作:
@IBAction func saveNameButton(_ sender: UIButton) {
let addressViewController = storyBoard.instantiateViewController(identifier: "AddressViewController") as? AddressViewController
addressViewController?.planDictionary = planDictionary
navigationController?.pushViewController(addressViewController!, animated: true)
}
当标签栏位于情节提要中时,按钮单击操作正在工作。但是在以编程方式重构之后,它不会将下一个 VC 放在导航堆栈上。
帮助将不胜感激。
解决方案
几乎肯定...
这一行:
let deliveryViewController = storyBoard.instantiateViewController(identifier: "DeliveryViewController") as? DeliveryViewController
正在实例化一个实例DeliveryViewController
并将其设置为选项卡的视图控制器。但是您要做的是加载一个UINavigationController
并制作DeliveryViewController
该 NavController 的根视图控制器,并将该 NavController 设置为 Tab 项。
推荐阅读
- google-analytics - 渠道归因、硬编码分析与标签管理器的差异
- javascript - 比较然后根据数组键输出值
- reactjs - React.js 显示 Pusher 捕获的数据/事件
- javascript - 如何在打字稿中按值搜索这种树结构而不会超出最大堆栈调用
- reactjs - webpack 选项有一个未知属性“hotOnly”。无效的选项对象。开发服务器已使用选项对象初始化
- node.js - npm install Cordova 失败
- node.js - 在 Expo / React Native 中将本地图像加载到 base64 中
- delphi - TMS TPlannerMonthView:获取所选项目文本
- vba - 如果主题在多个文本数组之一中匹配,则为传入邮件分配一个类别
- python - 如何在机器人框架的android应用程序中处理权限