Chi*_*hip 5 uitableview ios swift
我有一个 UITableViewController ,其中有一个原型单元。该单元格中有一个标签和一个文本字段,并且其类设置为InputCell。当表视图加载时,单元格似乎已出列,但显示为默认的空单元格。
我已经检查了以下事项:
func gototSettingsFor(control: EditableUIElement) {
let v = ControlSettingsView()
self.navigationController?.pushViewController(v, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
class InputCell: UITableViewCell {
@IBOutlet weak var cell_input: UITextField!
@IBOutlet weak var cell_title: UILabel!
}
Run Code Online (Sandbox Code Playgroud)
我希望在表格视图中显示 5 个自定义表格视图单元格,但是我只得到 5 个空单元格,我可以看到这些单元格在那里,因为如果我点击它们,它们就可以被选择。
我无法理解为什么该单元格不是自定义单元格而是一个空单元格。
故事板中有表视图控制器和原型单元。但是您正在以编程方式创建视图控制器
let v = ControlSettingsView()
Run Code Online (Sandbox Code Playgroud)
因此原型细胞属性将为零。使用故事板标识符创建视图控制器实例
确保您已ControlSettingsView
为视图控制器设置故事板标识符
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "ControlSettingsView") as? ControlSettingsView {
self.navigationController?.pushViewController(vc, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
如果故事板中有 tableview 单元格,请不要使用register(_:forCellReuseIdentifier:)方法。
归档时间: |
|
查看次数: |
1644 次 |
最近记录: |