UITableViewCell 中的 UITextField 错误
Bug with UITextField inside UITableViewCell
我对 UITableViewCell 中的某些 TextField 有疑问;我在 table 单元格中有两个文本字段,当我点击文本字段时,一切正常,如您在这两个屏幕截图中所见
1.
红色方块中的数字是我的 UITextField,当我点击其中一个时它工作正常
但是当我点击另一个文本字段时,整个单元格就这样消失了
点击另一个文本字段
后我有一个空的space
我没有实现任何功能,只有一个改变字体和文本颜色的功能
func setPickers() {
self.hourPicker.delegate = self
self.minutePicker.delegate = self
hourPicker.textColor = theme.grey
minutePicker.textColor = theme.grey
hourPicker.background = UIImage()
minutePicker.background = UIImage()
hourPicker.textAlignment = .center
minutePicker.textAlignment = .center
hourPicker.font = UIFont(name: "Roboto-Regular", size: 48)
minutePicker.font = UIFont(name: "Roboto-Regular", size: 48)
}
这是我故事板中的单元格
编辑 2
看看我的图形调试在错误之前显示了什么
然后是
单元格被称为EventDetailFooterTableViewCell
编辑 3
这是我为页脚
初始化 cellView 的地方
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "footerCell") as! EventDetailFooterTableViewCell
cell.event = self.event
cell.delegate = self
cell.setView()
cell.backgroundColor = theme.mainColor
return cell
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
var height: CGFloat = 180.0
var calendar = NSCalendar.current
calendar.timeZone = TimeZone(abbreviation: "UTC")! //OR NSTimeZone.localTimeZone()
let dateAtMidnight = calendar.startOfDay(for: Date())
let todayLong = dateAtMidnight.millisecondsSince1970
if let eventDay = event.dateTime?.millisecondsSince1970 {
if eventDay >= todayLong {
height = 280
}
}
return height
}
我看到一个问题。您正在使用常规单元格作为节页脚,这就是为什么您会看到不可预知的行为。您应该改用 UITableViewHeaderFooterView。如果你真的需要这样的设计。更好的解决方案是删除页脚并改为使用单元格。
我对 UITableViewCell 中的某些 TextField 有疑问;我在 table 单元格中有两个文本字段,当我点击文本字段时,一切正常,如您在这两个屏幕截图中所见
1.
红色方块中的数字是我的 UITextField,当我点击其中一个时它工作正常
但是当我点击另一个文本字段时,整个单元格就这样消失了
点击另一个文本字段
后我有一个空的space我没有实现任何功能,只有一个改变字体和文本颜色的功能
func setPickers() {
self.hourPicker.delegate = self
self.minutePicker.delegate = self
hourPicker.textColor = theme.grey
minutePicker.textColor = theme.grey
hourPicker.background = UIImage()
minutePicker.background = UIImage()
hourPicker.textAlignment = .center
minutePicker.textAlignment = .center
hourPicker.font = UIFont(name: "Roboto-Regular", size: 48)
minutePicker.font = UIFont(name: "Roboto-Regular", size: 48)
}
这是我故事板中的单元格
编辑 2 看看我的图形调试在错误之前显示了什么
然后是
单元格被称为EventDetailFooterTableViewCell
编辑 3 这是我为页脚
初始化 cellView 的地方func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "footerCell") as! EventDetailFooterTableViewCell
cell.event = self.event
cell.delegate = self
cell.setView()
cell.backgroundColor = theme.mainColor
return cell
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
var height: CGFloat = 180.0
var calendar = NSCalendar.current
calendar.timeZone = TimeZone(abbreviation: "UTC")! //OR NSTimeZone.localTimeZone()
let dateAtMidnight = calendar.startOfDay(for: Date())
let todayLong = dateAtMidnight.millisecondsSince1970
if let eventDay = event.dateTime?.millisecondsSince1970 {
if eventDay >= todayLong {
height = 280
}
}
return height
}
我看到一个问题。您正在使用常规单元格作为节页脚,这就是为什么您会看到不可预知的行为。您应该改用 UITableViewHeaderFooterView。如果你真的需要这样的设计。更好的解决方案是删除页脚并改为使用单元格。