【问题标题】:Is there a way to show the keyboard after the row has been inserted?插入行后有没有办法显示键盘?
【发布时间】:2020-06-13 17:12:39
【问题描述】:

我有一个表格视图单元格,里面有一个文本字段。

我希望它在插入行后成为第一响应者。但是插入完成后有没有明确的方法来获得回调?

我尝试在单元格的 viewWilDisplay 中调用 textField 的 becomeFirstResponder,结果只是冻结了 UI

【问题讨论】:

    标签: uitableview uiview uikit first-responder


    【解决方案1】:

    尝试使用batch update 插入行。该函数具有完成块,因此您可以从那里调用 becomeFirstResponder。

    【讨论】:

      【解决方案2】:

      我知道这有点傻,但对我很有帮助。

      首先创建一个 tempObject 来存储新行的 int 值。 例如:

      var insertCellIndex : Int = -1
      

      在 cellforIndex 方法中:

      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
      {
                  if self.insertCellIndex == indexPath.row
                  {
                    // make your textfield become first responder
                  }
                  else
                  {
                      print("nothing")
                  }
      }
      

      借助按钮插入新行

      @IBAction func btnApplyFilterClicked(_ sender: Any)
      {
          self.arrTemp.append("test") // insert in array
          self.insertCellIndex = self.arrTemp.count - 1
          self.tblView.reloadData()
      }
      

      【讨论】:

        猜你喜欢
        • 2011-06-24
        • 2011-07-24
        • 1970-01-01
        • 2011-11-06
        • 1970-01-01
        • 2015-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多