Remove `UIMenu` from `navigationBar.backBarButtonItem`

83 views Asked by At

With ios14, apple introduced the UIMenus we know to the navigation bar, so we could go back a couple of screens within a single long tap.

enter image description here

However, I want to remove that behavior from my app.

I tried doing a new class without setting the menu to the UIBarButtonItem and later on adding it to the navigation bar like shown below.

class BackBarButtonItem: UIBarButtonItem {
  @available(iOS 14.0, *)
  override var menu: UIMenu? {
    set {
      /* Don't set the menu here */
      /* super.menu = menu */
    }
    get {
      /* return nil doesn't work either */
      return super.menu
    }
  }
}
let backButton = BackBarButtonItem(title: "BACK", style: .plain, target: nil, action: nil)
navigationItem.backBarButtonItem = backButton

Doesn't work ^^^

navigationItem.backBarButtonItem?.menu = nil // still displays the menu

This didn't seem to work either.

How could I remove that menu?

0

There are 0 answers