UIDatePicker bug? UIControlEventValueChanged after hitting minimum internal

后端 未结 7 670
星月不相逢
星月不相逢 2020-12-08 05:21

I\'ve run into a weird effect that sure looks like a bug in iOS7 -- but often in the past, when I have thought I found a bug in Apple\'s APIs, it has turned out to be my own

7条回答
  •  [愿得一人]
    2020-12-08 05:33

    If someone still having problems with datepicker... I'm using Swift / iOS 8 / Xcode 6.3

    To solve the problem you should not use picker.countDownDuration = NSTimeInterval. Use .setDate(NSDate, animated: true).

    it works direct on viewDidLoad(), don't need to use queues

    The complete snippet:

    override func viewDidLoad() {
        super.viewDidLoad()
        picker.setDate(setDateFromSeconds(seconds), animated: true)
    }
    
    func setDateFromSeconds(seconds: Double) -> (NSDate) {
        let intSeconds = Int(seconds)
        let minutes = (intSeconds / 60) % 60
        let hours = intSeconds / 3600
        let dateString = NSString(format: "%0.2d:%0.2d", hours, minutes)
    
        let dateFormatter = NSDateFormatter()
        dateFormatter.dateFormat = "hh:mm"
        return dateFormatter.dateFromString(dateString as String) as NSDate!
    }
    

提交回复
热议问题