项目中用到了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一直卡在屏幕中无法收回,请教大家解决方案,非常感谢
业精于勤,荒于嬉;行成于思,毁于随。