ios - 找不到 tableViewCell 不可编辑且未显示默认文本的原因
问题描述
抱歉这个无知的问题,但我正在尝试按照我学校的 appdev 教程进行操作,但我遇到了一个错误,我试图创建可编辑的表格视图单元格,但默认文本和编辑能力都没有出现。我签入了自定义 TableViewCell 类,TextView 插座就在那里。任何帮助将不胜感激:3
import UIKit
class AddVerbViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource{
var isPickerViewOpened : Bool = false
@IBOutlet weak var TableView: UITableView!
@IBAction func DoneButtonTapped(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
@IBAction func ClearButtonTapped(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
TableView.delegate = self
TableView.dataSource = self
print("yes")
// Do any additional setup after loading the view.
}
//MARK: - Table View Methods
func numberOfSections(in tableView: UITableView) -> Int {
print("number of sections : 2")
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0){
return 2
} else {
return 2
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "AddVerbCell", for: indexPath)as! AddVerbTableViewCell
cell.TextView.textContainer.maximumNumberOfLines = 1
cell.TextView.textContainer.lineBreakMode = .byTruncatingTail
cell.PickerView.isHidden = true
if (indexPath.section == 0) {
cell.TextView.isEditable = true
cell.TextView.textColor = UIColor.gray
cell.TextView.isScrollEnabled = false
if (indexPath.row == 0){
print("cell Name")
cell.TextView.text = "Name"
} else {
cell.TextView.text = "TeForm"
}
} else {
if (indexPath.row == 0) {
cell.TextView.isEditable = false
cell.TextView.isSelectable = false
cell.TextView.textColor = UIColor.black
cell.TextView.text = "PotentialForm"
} else {
cell.TextView.isHidden = true
cell.PickerView.isHidden = false
}
}
return cell
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 20
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (indexPath.section == 0) {
return 50
} else {
if (indexPath.row == 0){
return 50
} else {
return 100
}
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
解决方案
我真的想通了。所以我需要添加cell.TextView.isUserInteractionEnabled = true
到适当的区域。现在它起作用了!给大家添麻烦了抱歉
推荐阅读
- python - 如何使用 Pandas 将 DataFrame 从 HTML 转换为 SQL 并将其用于 Flask 中的搜索字段?
- firebase - Firestore composite Indexing not working: The query requires an index
- vim - Vim 和终结者编程环境
- java - Telegram,Java:上传文件以在 sendAnimation 中发送
- javascript - 如何修复javascript中的settimeout内存泄漏问题
- sql - 使用来自子查询的多个值进行更新
- c++ - 通过函数释放内存 - 这是对的吗?
- sql - 如何使用 distinct 和 sum 编写 SQL 报告
- python - 将多索引数据帧写入 csv 而不更改其格式
- php - PHP Wordpress:在 Safari 中 print_r() 输出到哪里?