首页 > 解决方案 > 我想使用 Swift 4.2 到 5.1 在 TableView 中选择“其他”单元格时显示另一个单元格

问题描述

   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {



    let tblContent = tblViewCustomFields[indexPath.row]

    let title = tblContent
    let custmCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CustomCellForLetKnowUs

    let customTextCell = tableView.dequeueReusableCell(withIdentifier: "textCell") as! CustomTextCell

    custmCell.lblInfo.text = title
    if indexPath.row == 7 {
        //            cellList.append(.withTxtFld)
        //            tableView.reloadData()
        customTextCell.textView.isHidden = true
    }

    return custmCell

}

标签: iosswiftuitableview

解决方案


尝试这样做

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     if indexPath.row == 7 { 
          let customTextCell = tableView.dequeueReusableCell(withIdentifier: "textCell") as! CustomTextCell
          customTextCell.textView.isHidden = true
          return customTextCell
     }


     let custmCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CustomCellForLetKnowUs
     custmCell.lblInfo.text = tblViewCustomFields[indexPath.row] ?? ""

     return custmCell
}

推荐阅读