混合程序化和故事板。单击按钮将不会在导航控制器中打开下一个 VC
Mixed programmatic and storyboard. Button click will not open next VC in a navigation controller
我有一个以编程方式构建的标签栏控制器。它看起来像这样:
class 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项。
我有一个以编程方式构建的标签栏控制器。它看起来像这样:
class 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项。