ios - 开发用到datePicker设置好属性后发现值无法改变
迷茫
迷茫 2017-04-17 13:41:27
0
0
492

项目中用到了datepicker,发现无法获取到datepicker改变后的值代码如下

      datePicker.frame = CGRectMake(self.view.frame.size.height, 320, 320, 200)
            datePicker.timeZone = NSTimeZone(name: "GMT+8")
            datePicker.datePickerMode = UIDatePickerMode.Date
            var miniDate = NSDateFormatter()
            miniDate.dateFormat = "yyyy-MM-dd"
            let minDate:NSDate = miniDate.dateFromString("1920-01-01")!
            let maxDate:NSDate = NSDate()
            datePicker.backgroundColor = UIColor.whiteColor()
            datePicker.minimumDate = minDate
            datePicker.maximumDate = maxDate
            datePicker.addTarget(self, action: "datePicker:", forControlEvents:.ValueChanged)
            self.view .addSubview(datePicker)
            UIView .animateWithDuration(0.5, animations: {
            self.datePicker.frame = CGRectMake(0, self.view.frame.size.height-216, 320, 216)
            })

值改变的时候是这么写的

 func datePicker(picker:UIDatePicker) {
    var datePicker_one:UIDatePicker = picker as UIDatePicker
    var date_one:NSDate = datePicker_one.date
    var formatter:NSDateFormatter = NSDateFormatter()
    formatter.dateFromString("yyyy-MM-dd")
    dateLabel.text = formatter .stringFromDate(date_one)
}

结果是label的text值并未改变而且datepicker一直卡在屏幕中无法收回,请教大家解决方案,非常感谢

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

Antworte allen(0)
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!