簡體   English   中英

如何讓 UITextView 檢測到點擊表格單元格

[英]How to make a UITextView detect the click on table cell

我正在開發一個項目,其中一個表視圖的文本是 UITextView,但另一個是 UILabel。 UILabel 將用戶的點擊檢測為對表格單元格的點擊,但 UITextView 沒有。 為什么會這樣? 有什么辦法可以解決嗎?

確保 textView 的 isSelectable 屬性為真。

我想通了,單元格視圖和文本視圖都是scrow視圖,總是會有沖突,所以我需要取消選中文本視圖的UserInteractions和Multiple Touch,將booth設置為false

試試看

yourTextView.addTarget(self, action: #selector(myTargetFunction), for: .touchDown)
@objc func myTargetFunction(textField: UITextView) {
      print("myTargetFunction")

}

我不確定您是在談論UITableView行還是UITextView / UILabel本身的選擇。

如果您嘗試在UILabelUITextView上設置手勢識別器,我想知道這是否有必要,或者您是否可以在視圖 controller 中使用didSelectRowAtIndexPath

例如

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let cell = tableView.cellForRow(at: indexPath)
    yourMethodHere(for: cell)
  }

然后,您將在yourMethodHere()中定義選擇單元格時希望發生的行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM