gpt4 book ai didi

ios - Swift:出现键盘时滚动 UITableView

转载 作者:搜寻专家 更新时间:2023-10-31 23:09:15 25 4
gpt4 key购买 nike

我已经找到了这个问题的答案,但我无法为我的具体案例找到答案。

我有一个带有动态原型(prototype)单元格的 UITableView。其中一个单元格只包含一个 UITextView,并且始终只有其中一个,并且始终位于最底部。这是唯一的 TextView 。

我无法将此 TextView 连接到 Controller 中的 socket ,因为它会引发错误(我假设是因为 TextView 可能有多个实例,并且它们不能全部映射到一个 socket ) .所以我不能让我的 Controller 符合 UITextView 协议(protocol)。

是否有一个简单而优雅的解决方案?

最佳答案

尝试在你的 VC 中观察键盘出现事件。像这样:

NotificationCenter.default.addObserver(self, selector: #selector(scrollToTop(notification:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(scrollToBottom(notification:)), name: .UIKeyboardWillHide, object: nil)

func scrollToTop(notification: NSNotification) {
//change tableView insets
}


func scrollToBottom(notification: NSNotification) {
//change tableView insets
}

关于ios - Swift:出现键盘时滚动 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45378359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com