         addTarget(self, action: #selector(toggle), for: .touchUpInside)
         
         sizeToFit()
+    }
+    
+    // If the popover has been presented and then the button's view controller is dismissed due to an event other
+    //  than a screen touch, the popover will stay on the screen. Let's detect that and dismiss the popover if it occurs
+    public override func didMoveToSuperview() {
+        super.didMoveToSuperview()
+        if superview == nil, let popover = popoverViewController {
+            popover.dismiss(animated: true, completion: nil)
+        }
     }
     
     public override func layoutSubviews() {

            
            super.init(items: items)
        }
    }
    
    private class MenuViewController: DropDownListButton.ListViewController {

        return self
    }

    public var selectedItem: CustomStringConvertible? {
        return menu?.selectedItem
    }

    fileprivate override func makePopoverViewController() -> UIViewController? {
        guard let menu = self.menu else { return nil }
        return MenuViewController(menu: menu)
    }
}

public class DropDownBarButton: UIBarButtonItem {
    
