Remove TabBar item in Swift

前端 未结 5 1209
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 05:17

I currently try to find a way to remove while run the app a TabBar Item, i found a way to enable or disable it but not to complete remove it.

For disable it i do:

5条回答
  •  爱一瞬间的悲伤
    2020-12-06 05:48

    Swift 5: For removing only one index in Tab Bar Controller(you can use this method in viewDidLoad and viewDidAppear both of them)

    override func viewDidAppear(_ animated: Bool) {
    
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    
    }
    
    tabBarController.viewControllers?.remove(at:0)  // for 0 index
    tabBarController.viewControllers?.remove(at:1)  // for 1 index
    tabBarController.viewControllers?.remove(at:2)  // for 2 index
    

    if you have 4 index in Tab Bar and you want to remove the last 2 index

    tabBarController.viewControllers?.remove(at:2)
    tabBarController.viewControllers?.remove(at:2)
    

    first line will remove the index 3rd one and you will remaining 3 from 4 and again when you remove the 2nd index it will remove again 3rd index and then you will have remain 2 index in last.

提交回复
热议问题