【问题标题】:Bug with UITextField inside UITableViewCellUITableViewCell 中的 UITextField 错误
【发布时间】:2018-12-13 11:44:17
【问题描述】:

我在 UITableViewCell 中的一些 TextField 有问题;我在表格单元格中有两个文本字段,当我点击文本字段时,一切正常,正如您在这两个屏幕截图中看到的那样

1.

红色方块中的数字是我的 UITextField,当我点击其中一个时,它可以正常工作

但是当我点击另一个文本字段时,整个单元格会像这样消失

单击另一个文本字段后我有一个空白区域

我没有实现函数,只有一个改变字体和文本颜色的函数

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 看我的图形调试bug之前显示的内容

然后

该单元格被称为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
}

【问题讨论】:

  • 点击此单元格上的空白区域会发生什么? Mb 你通过 Storyboard 添加了一些 segue 或行为?
  • 你在使用 UITableViewController 吗?
  • 不,我在 UIViewController 中使用 UITableView,当我点击单元格中的空白区域时,没有任何反应:/
  • 我认为它与 textField 的 endEditing 冲突
  • 看起来键盘显示/隐藏事件以某种方式影响单元格或表格。您是否使用某些 3d 库在显示键盘时自动向上移动视图?

标签: ios swift uitableview uitextfield


【解决方案1】:

我发现了一个问题。您正在使用常规单元格作为部分页脚,这就是为什么您会看到不可预测的行为。您应该改用 UITableViewHeaderFooterView 。如果你真的需要这样的设计。更好的解决方案是删除页脚并改为单元格。

【讨论】:

  • 哦,我从来不知道 UITableViewHeaderFooterView 但我解决了删除页脚并将其作为普通单元格的问题;不管怎样,谢谢你的帮助
猜你喜欢
  • 1970-01-01
  • 2011-09-19
  • 1970-01-01
  • 2019-11-27
  • 2010-09-25
  • 2011-06-01
相关资源
最近更新 更多