0

enter image description here enter image description here

When the UITableView cell is clicked, popup menu appears from bottom with animation and covers tab bar.
I want to prevent tab bar item's click event when cell is clicked and popup menu is appearing.
So I made a custom UITabBarController which comforms UITabBarContorllerDeleagte like below

// CustomTabBarController.swift
class CustomTabBarController: UITabBarController, UITabBarControllerDelegate {
    var enabled = true 
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        return enabled
    }
} 

instance property enabled is set to false when table cell is clicked and to true when popup menu disappears.
The problem is that when I click cell and tab bar sequentially very quickly, popup menu appears and also tab is changed. I think tab bar item click event is executed before variable enabled's change.
Using UITabBarController's isUserInteractionEnabled and disable each tab bar item have a same result. How can I fix this?

soonoo
  • 867
  • 1
  • 10
  • 35

2 Answers2

0

When the cell is clicked, you can set tabBarController?.tabBar.isUserInteractionEnabled = false. In the completion handler of the popup, after being closed, set tabBarController?.tabBar.isUserInteractionEnabled = true

Toma Radu-Petrescu
  • 2,152
  • 2
  • 23
  • 57
0

add this on your table view delegate

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    let tabBarController: CustomTabBarController = ... // get your tabbar
    tabBarController.enabled = false
}
Rei
  • 512
  • 1
  • 7
  • 18