致命错误: init(编码器:) 尚未实现错误



Xcode向我发送错误"致命错误:init(coder:(尚未实现错误"尽管已实现。我不知道问题出在哪里。

final class newTableViewController: UITableViewController {
@IBOutlet var inputFormTableView: UITableView!
let form: Form
let note = Note(name: "")
init(form: Form) {
self.form = form
super.init(style: .grouped)
}
convenience init(note: Note) {
let form = Form(sections: [
FormSection(items: [
TextInputFormItem(text: note.name,
placeholder: "Add title",
didChange: { _ in print("hello")})
])
])
self.init(form: form)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
inputFormTableView.rowHeight = 44
inputFormTableView.register(TextInputTableViewCell.self, forCellReuseIdentifier: ReuseIdentifiers.textInput.rawValue)
let new = newTableViewController(note: note)
print(new.note.name)
}
private enum ReuseIdentifiers: String {
case textInput
}
// MARK: - Table view data source
private func model(at indexPath: IndexPath) -> FormItem {
return form.sections[indexPath.section].items[indexPath.item]
}
override func numberOfSections(in tableView: UITableView) -> Int {
return form.sections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return form.sections[section].items.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let object = model(at: indexPath)
if let textRow = object as? TextInputFormItem {
let cell = tableView.dequeueReusableCell(withIdentifier: ReuseIdentifiers.textInput.rawValue, for: indexPath) as! TextInputTableViewCell
cell.configure(for: textRow)
return cell
}
else {
fatalError("Unknown model (object).")
}
}
}

我正在尝试使UITableView像输入表单一样。为此,我遵循以下教程:https://augmentedcode.io/2018/11/04/text-input-in-uitableview/。一切都在示例项目中有效,但不适用于我的。

你还没有实现它,你只是抛出了一个致命错误,当从故事板运行时,这个init正在执行,替换以下代码:

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

有了这个:

required init?(coder: NSCoder) {
form = Form()
super.init(coder: coder)
}

最新更新