混合编程和故事板。在导航控制器中点击按钮不会打开下一个VC。

问题描述 投票:0回答:1

我有一个标签栏控制器,是通过编程建立的。它看起来像这样。

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
}

现在在storyboard中创建这个DeliveryViewController,并将其嵌入到一个导航控制器中。

它有一个按钮点击的动作。

@IBAction func saveNameButton(_ sender: UIButton) {



let addressViewController = storyBoard.instantiateViewController(identifier: "AddressViewController") as? AddressViewController
                addressViewController?.planDictionary = planDictionary
                navigationController?.pushViewController(addressViewController!, animated: true)
}

当tabbar在storyboard中时,按钮点击的动作是有效的。 但在程序化重构后,它没有将下一个VC放在导航堆栈上。但是在程序上重构后,它是不把下一个VC放在导航栈上。

希望得到帮助。

swift uinavigationcontroller uitabbarcontroller
1个回答
1
投票

几乎可以肯定...

这一行。

let deliveryViewController = storyBoard.instantiateViewController(identifier: "DeliveryViewController") as? DeliveryViewController

是实例化一个 DeliveryViewController 并将其设置为Tab的视图控制器。但您要做的是 想要 要做的是加载一个 UINavigationController 并使 DeliveryViewController 的根视图控制器,并将该NavController设置为Tab项。

© www.soinside.com 2019 - 2024. All rights reserved.