         else {
             del?.WWCalendarTimeSelectorCancel?(picker, dates: multipleDates)
         }
-        del?.WWCalendarTimeSelectorWillDismiss?(picker)
-        dismiss(animated: true) {
-            del?.WWCalendarTimeSelectorDidDismiss?(picker)
-        }
+        dismiss()
     }
     
     @IBAction func done() {

    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]))

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