It's my understanding that with iOS 7, 8 and 9, when you present a popover in your application, all UIBarButtonItems in a UIToolbar are supposed to automatically be grayed out.
However, most of the time what I get is that only the button you tapped turns gray, and the other buttons remain in their original color.
I built a simple test app with a story board that has:
- a single UIViewController embedded in a UINavigationController
- a UIToolbar on that UIViewController
- five UIBarButtonItems in the toolbar (using images)
- segues set to "Present As Popover" from each of the bar button items to another UIViewController
In code, for the UIViewController that presents the popover I have just this:
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowPopover" {
let popoverViewController = segue.destinationViewController
popoverViewController.preferredContentSize = CGSizeMake(320.0, 224.0)
if let popoverController = popoverViewController.popoverPresentationController {
// set the delegate, so adaptivePresentationStyleForPresentationController is called
popoverController.delegate = self
}
}
}
// MARK: - UIAdaptivePresentationControllerDelegate
// return .None to show as a popover on iPhone too
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .None
}
}
Even with that simple example, when I tap one of the buttons to present the popover, only the tapped button turns gray.
Am I misunderstanding the way UIBarButtonItems are supposed to behave when a popover is presented? Or is this a known iOS SDK bug? Are there any workarounds?
Update: I've posted a sample application here that demonstrates the problem, using the iOS 8.4 SDK: https://dl.dropboxusercontent.com/u/2349787/BarButtonPopover.zip