我有一个UITabBarController。使用界面构建器我添加了多个视图控制器。这些viewControllers都是同一个类,但唯一改变的是参数。
我想扩展UITabBarController,以便在初始化视图控制器时添加此参数,但我不知道如何在UITabBarController扩展中执行此操作。这是哪个地方?
答案 0 :(得分:1)
我也面临这样的问题,我想在标签栏控制器的第五个标签中显示弹出视图控制器, 我用过这个:
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if(viewController == tabBarController.viewControllers?[4]){
let storyboard : UIStoryboard = UIStoryboard(name: "AfterLogin", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MorePopUpVC")
vc.modalPresentationStyle = .popover
let popover = vc.popoverPresentationController
popover?.delegate = self
popover?.permittedArrowDirections = .down
popover?.sourceView = self.tabBar
popover?.sourceRect = ((self.orderedTabBarItemViews()).last?.frame)!
vc.preferredContentSize = CGSize(width: 120, height: 132)
present(vc, animated: true, completion:nil)
return false
}
return true
}
这是我改变第五个标签的动作,
您可以像:
一样使用它func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
let storyboard : UIStoryboard = UIStoryboard(name: "YOUR STORYBOARD NAME", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "YOUR VIEW CONTROLLER IDENTIFIER")
if(viewController == tabBarController.viewControllers?[4]){
vc.type = "PARAMETER YOU WANT"
}
present(vc, animated: true, completion:nil)
return false
}
我认为这有帮助。