0

I've used UIBarButtonItem(title:image:primaryAction:menu:), with nil for primary action, and only a UIMenu for iOS / macOS and it has been working fine for iOS / iPadOS 14,15,16 and macOS 11 and 12.

Now for macOS 13 (Ventura), where the navigation bar has been moved to the title bar, the UIBarButton item is disabled and does not show the UIMenu when tapped. This is a huge problem for my apps now. If a primary action is defined, then the UIBarButtonItem is enabled, and shows a dropdown arrow to the right of the item that activates the UIMenu option.
Is this a bug with macOS 13? I've filed a report with Apple but no response yet.

Progman
  • 16,827
  • 6
  • 33
  • 48
gbotha
  • 1,231
  • 17
  • 23

1 Answers1

1

I've managed to find a workaround by creating a custom UIBarButton Item.

  1. Create a UIButton.
  2. Assign its showsMenuAsPrimaryAction property to true
  3. Assign a UIMenu to its menu property.
  4. Assign the UIButton to a UIBarButtonItem like this.

let newBarButton = UIBarButtonItem(customView: buttonPDF)

Now the UIMenu shows when tapping the navbar button in macOS 13.

gbotha
  • 1,231
  • 17
  • 23
  • your workaround seems to work but does not show an icon - did you figure out how to have an icon image? (I tried to attach an image to both the UIButton and the UIBarButtonItem...) – Aviel Gross Jan 14 '23 at 20:30
  • Yes, creating a custom button with image worked fine for me as well. However, due to other bugs with the new navigation bar, I have just set the navigation bar to .ipad style, the previous style. #if targetEnvironment(macCatalyst) if #available(macCatalyst 16.0, *) { self.navigationController?.navigationBar.preferredBehavioralStyle = .pad } #endif – gbotha Jan 15 '23 at 17:26