How to get the previous viewcontroller that pushed my current view

后端 未结 10 388
礼貌的吻别
礼貌的吻别 2020-12-28 14:08

The home page of my app has UIButtons, btnIncome and btnExpense. Pressing on this buttons pushes IncomeVC and Expen

10条回答
  •  有刺的猬
    2020-12-28 14:37

    Swift

    extension UINavigationController {
        func getPreviousViewController() -> UIViewController? {
            let count = viewControllers.count
            guard count > 1 else { return nil }
            return viewControllers[count - 2]
        }
    }
    

提交回复
热议问题