【发布时间】:2015-01-28 15:58:00
【问题描述】:
我正在尝试将 UIDatePicker 放入通过单击其上方的单元格来打开/关闭的 UITableViewCell 中。选择器似乎呈现所有错误。首先,这是 UITableView 类的相关代码:
// Determines if the date picker should be shown
var editingDate: Bool = false
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 1 && indexPath.row == 1 { // Picker cell
if !self.editingDate {
return 0
}
}
return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 1 && indexPath.row == 0 { // Date cell
self.editingDate = !self.editingDate
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: 1, inSection: 1)], withRowAnimation: .Fade)
}
}
情节提要中的表格:
我已在情节提要中将表格单元格设置为自定义高度 219。下面是我当前单击日期字段时发生的情况的动画 GIF。抱歉质量太差了。
我注意到我们可以从上面的动画 gif 中看到单元格背景变得透明(不是白色),这意味着单元格的内容视图没有拉伸到完整高度。我想知道为什么会这样?
编辑:这是用于 DatePicker 的约束:
【问题讨论】:
标签: ios uitableview swift uidatepicker