[英]Change the UIVIewController of a tab in UITabBarController
[英]UITabBarController how to display different UIViewController by pressing tab
我有一個帶有5個選項卡的UITabBarController。 通過按Tab鍵我想做一個簡單的檢查,以確定我的UITabBarController應該通過按Tab鍵顯示哪個UIViewController。
有什么更好的方法呢?
試試這個吧
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//here it provide the viewController
}
我認為你可以通過實現tabBarController(_:didSelect :) (符合UITabBarControllerDelegate )來實現。
它應該類似於(Swift 3):
class ViewController: UIViewController, UITabBarControllerDelegate {
//...
override func viewDidLoad() {
super.viewDidLoad()
// don't forget to:
tabBarController?.delegate = self
}
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
// here, you can determine what's the selected view controller by checking "viewController":
if viewController is ViewController {
// the current selected view controller is "ViewController"
}
}
//...
}
創建一個tabbar控制器類,將該類分配給tabbar並覆蓋該方法
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
// your code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.