使用特定时间设置 Eureka DateTimeRow
Set Eureka DateTimeRow with specific time
我正在尝试设置 DateTimeRow() 的开始时间,这样每当我单击日期时,DateTime 选择器时间就会旋转到 7:30 AM。
以下代码仅更改显示文本而不旋转日期选择器:
row = DateTimeRow() {
[=10=].minuteInterval = 30
}.onCellSelection({(cell,row) in
if row.baseCell.detailTextLabel?.text == nil {
// Setup the start date
var currentDate = NSDate() as Date
currentDate = currentDate.setHoursMinutes(hour: 7, minute: 30)
let dateFormatter = DateFormatter()
dateFormatter.timeStyle = .short
dateFormatter.dateStyle = .short
dateFormatter.locale = NSLocale.current
// This will show the current day date with time of 7:30 AM
row.baseCell.detailTextLabel?.text = dateFormatter.string(from: currentDate)
}
有没有办法直接访问选择器并像这样调用 setDate:
timePicker.setDate([My Date here], animated: true)
谢谢你
我一直在研究你的问题,首先你要在 onCellSelection
回调上设置你的单元格我认为你需要在单元格创建时设置你的日期值,就像这样
<<< DateTimeRow() {
var currentDate = Date()
currentDate = currentDate.setHoursMinutes(hour: 7, minute: 30)
[=10=].value = currentDate
}
或者您需要使用 cellSetup
回调,如果您想要显示不同的日期时间,则需要实施 onCellSelection
回调
<<< DateTimeRow().cellSetup({ (dateCell, dateTimeRow) in
// Setup the start date
let currentDate = Date()
currentDate = currentDate.setHoursMinutes(hour: 7, minute: 30)
dateTimeRow.dateFormatter?.dateStyle = .short
dateTimeRow.dateFormatter?.timeStyle = .short
//dateFormatter.locale = NSLocale.current
dateCell.row.value = currentDate
}).onCellSelection({ (cell, row) in
//If you want to show different date
let currentDate = NSDate() as Date
currentDate.setHoursMinutes(hour: 9, minute: 30)
cell.datePicker.date = currentDate
})
希望对您有所帮助,祝好
我正在尝试设置 DateTimeRow() 的开始时间,这样每当我单击日期时,DateTime 选择器时间就会旋转到 7:30 AM。
以下代码仅更改显示文本而不旋转日期选择器:
row = DateTimeRow() {
[=10=].minuteInterval = 30
}.onCellSelection({(cell,row) in
if row.baseCell.detailTextLabel?.text == nil {
// Setup the start date
var currentDate = NSDate() as Date
currentDate = currentDate.setHoursMinutes(hour: 7, minute: 30)
let dateFormatter = DateFormatter()
dateFormatter.timeStyle = .short
dateFormatter.dateStyle = .short
dateFormatter.locale = NSLocale.current
// This will show the current day date with time of 7:30 AM
row.baseCell.detailTextLabel?.text = dateFormatter.string(from: currentDate)
}
有没有办法直接访问选择器并像这样调用 setDate:
timePicker.setDate([My Date here], animated: true)
谢谢你
我一直在研究你的问题,首先你要在 onCellSelection
回调上设置你的单元格我认为你需要在单元格创建时设置你的日期值,就像这样
<<< DateTimeRow() {
var currentDate = Date()
currentDate = currentDate.setHoursMinutes(hour: 7, minute: 30)
[=10=].value = currentDate
}
或者您需要使用 cellSetup
回调,如果您想要显示不同的日期时间,则需要实施 onCellSelection
回调
<<< DateTimeRow().cellSetup({ (dateCell, dateTimeRow) in
// Setup the start date
let currentDate = Date()
currentDate = currentDate.setHoursMinutes(hour: 7, minute: 30)
dateTimeRow.dateFormatter?.dateStyle = .short
dateTimeRow.dateFormatter?.timeStyle = .short
//dateFormatter.locale = NSLocale.current
dateCell.row.value = currentDate
}).onCellSelection({ (cell, row) in
//If you want to show different date
let currentDate = NSDate() as Date
currentDate.setHoursMinutes(hour: 9, minute: 30)
cell.datePicker.date = currentDate
})
希望对您有所帮助,祝好