         case .range:
             del?.WWCalendarTimeSelectorDone?(picker, dates: optionCurrentDateRange.array)
         }
+        dismiss()
+    }
+    
+    fileprivate func dismiss() {
+        let picker = self
+        let del = delegate
         del?.WWCalendarTimeSelectorWillDismiss?(picker)
-        dismiss(animated: true) {
+        if let navigationController = self.navigationController {
+            navigationController.popViewController(animated: true)
             del?.WWCalendarTimeSelectorDidDismiss?(picker)
+        } else if presentingViewController != nil {
+            dismiss(animated: true) {
+                del?.WWCalendarTimeSelectorDidDismiss?(picker)
+            }
         }
     }
     

    open override func viewDidLoad() {
        super.viewDidLoad()
        
        // Add background
        let background = UIVisualEffectView(effect: UIBlurEffect(style: optionStyleBlurEffect))
        background.translatesAutoresizingMaskIntoConstraints = false
        view.insertSubview(background, at: 0)
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[bg]|", options: [], metrics: nil, views: ["bg": background]))

        else {
            del?.WWCalendarTimeSelectorCancel?(picker, dates: multipleDates)
        }
        dismiss()
    }
    
    @IBAction func done() {
