很抱歉,这个愚昧的问题,但是我试图遵循我学校的appdev教程,却遇到了一个错误,我试图创建可编辑的表格视图单元格,但是默认文本和编辑能力都没有出现。我签入了自定义TableViewCell类,并且那里有TextView Outlet。任何帮助将不胜感激: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.
}
*/
}
答案 0 :(得分:0)
我实际上知道了。
因此,我需要将cell.TextView.isUserInteractionEnabled = true
添加到适当的区域。现在可以了!
抱歉给大家带来麻烦