我有一个带有单个原型单元的UITableViewController。单元格中具有标签和文本字段,并且其类设置为InputCell。加载表视图时,该单元似乎已出队,但显示为默认的空单元。
我检查了以下内容:
func gototSettingsFor(control: EditableUIElement) {
let v = ControlSettingsView()
self.navigationController?.pushViewController(v, animated: true)
}
class ControlSettingsView: UITableViewController {
let INPUT_CELL: String = "input_cell"
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(InputCell.self, forCellReuseIdentifier: INPUT_CELL)
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch (section) {
case 0:
return 5
default:
return 0
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch (indexPath.section) {
case 0:
let cell: InputCell = tableView.dequeueReusableCell(withIdentifier: INPUT_CELL, for: indexPath) as! InputCell
return cell
default:
return tableView.dequeueReusableCell(withIdentifier: INPUT_CELL, for: indexPath)
}
}
}
class InputCell: UITableViewCell {
@IBOutlet weak var cell_input: UITextField!
@IBOutlet weak var cell_title: UILabel!
}
我希望在表格视图中显示5个自定义表格视图单元格,但是我只得到5个空单元格,因此可以看到那里的单元格,因为如果我点击它们,就可以选择它们。
我无法理解为什么该单元格不是自定义单元格而是空的单元格。
您在情节提要中具有表视图控制器和原型单元。但是您正在以编程方式创建视图控制器
let v = ControlSettingsView()
因此原型单元的属性将为零。使用情节提要标识符创建视图控制器实例
确保已ControlSettingsView
为视图控制器设置情节提要标识符
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "ControlSettingsView") as? ControlSettingsView {
self.navigationController?.pushViewController(vc, animated: true)
}
如果故事板中有表格视图单元,则不要使用register(_:forCellReuseIdentifier :)方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句