我正在用Mac Catalyst将我的iPad应用适配到Mac上,但我得到了一个不寻常的行为。UITextView
里面 UITableViewCell
. 当我呈现视图时,我自动将文本视图放在焦点上,但在Mac上无论我在其中输入什么。大写. 这从来没有发生在iPhone或iPad版本。我不知道为什么会发生这种情况(我的大写字母锁没有打开),我已经尝试了多个键盘,得到的结果是一样的。它也不是每次都发生,它是非常随机的。
这是我的代码。
class TextViewCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
textView.delegate = self
textView.isScrollEnabled = false
textView.returnKeyType = .done
}
//populate funcion called by the tableview. Just sets the textView into focus if it's the first time the view shows
func populate(isFirstLoad: Bool = false) {
//I set isFirstLoad to false after calling on this function in the tableview so this is only called on once
if isFirstLoad {
self.titleTF.becomeFirstResponder()
}
}
}
// MARK: - textView functions
extension TextViewCell: UITextViewDelegate {
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if (text == "\n") {
textView.resignFirstResponder()
return false
}
return true
}
}
有谁遇到过这个问题 知道怎么解决吗?
我过去也有同样的问题。由于是在Mac上,我认为不需要大写,所以只需设置为 textView.autocapitalizationType = .none
就不会出现那种奇怪的BUG了。你也可以把它包在一个 #if targetEnvironment(macCatalyst)
所以它只能在Mac上做这个