【发布时间】:2018-06-05 21:57:38
【问题描述】:
我有一个UIDatePicker,我按照下面的代码打印选定的日期。但是,它不打印所选日期,只打印当前日期。
@objc func setupDiscoverButton() {
let cell = Bundle.main.loadNibNamed("FirstTableViewCell", owner: self, options: nil)?.first as! FirstTableViewCell
// Date
let sessionDate = cell.datePicker.date
print("date: \(sessionDate)")
}
这是我为UIDatePicker 定义的地方。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("FirstTableViewCell", owner: self, options: nil)?.first as! FirstTableViewCell
// Date & time picker
cell.datePicker.minimumDate = Date()
cell.datePicker.timeZone = TimeZone.current
// Discover button
cell.discoverButton.addTarget(self, action: #selector(setupDiscoverButton), for: .touchUpInside)
return cell
}
【问题讨论】:
-
分享你的日期选择器代码
-
@AbdelahadDarwish 我已经添加了这个
-
@AbdelahadDarwish 它是在 Storyboard 中制作的 - 我必须实现其他方法吗?
标签: ios swift uidatepicker