【问题标题】:Textview in tableview is sets text to all caps [Mac Catalyst]tableview 中的 Textview 将文本设置为全部大写 [Mac Catalyst]
【发布时间】:2020-04-26 18:36:59
【问题描述】:

我正在使用 Mac Catalyst 将我的 iPad 应用程序调整为 Mac,并且在 UITableViewCell 中出现 UITextView 的异常行为。当我呈现视图时,我会自动将 textview 置于焦点位置,但在 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
     }
}

有其他人遇到过这个问题并知道如何解决吗???

【问题讨论】:

    标签: swift xcode uitextview mac-catalyst


    【解决方案1】:

    我过去也遇到过同样的问题。由于它在 Mac 上,我认为不需要大写,所以只需设置 textView.autocapitalizationType = .none 就不会出现那个奇怪的错误。您也可以将其包裹在 #if targetEnvironment(macCatalyst) 中,这样它只会在 Mac 上执行此操作

    【讨论】:

    • 这行得通!有趣的是我们必须这样做
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多