Reputation: 2457
I have a table view that I need to populate with dynamic data.
I did it previously in a separate controller and just copied everything over.
However, this time I keep on getting a SIGABRT error. I've found out that it's whenever I include these two line it errors out
// editJobTable.dataSource = self
// editJobTable.delegate = self
Here is my full view controller
import Foundation
import UIKit
class HelloworkJobsEditJobViewController: UIViewController{
fileprivate var presenter: HelloworkJobsEditJobPresenter?
@IBOutlet weak var editJobTable: UITableView!
func inject(presenter: HelloworkJobsEditJobPresenter) {
self.presenter = presenter
}
var helloworkJob: HelloworkJob!
override func viewDidLoad(){
super.viewDidLoad()
helloworkJob = presenter?.getHelloworkJob()
editJobTable.dataSource = self
editJobTable.delegate = self
// editJobTable.reloadData()
}
@IBAction func tapCloseButton(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
}
extension HelloworkJobsEditJobViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return 7
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("\(#line): \(#function) \(indexPath.row)")
let cellIdentifier = "HelloworkJobsEditJobCell"
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? HelloworkJobsEditJobCell else {
fatalError("The dequeued cell is not an instance of HelloworkJobsEditJobCell.")
}
cell.cellLabel.text = "labeltest"
cell.cellTextField.text = "textfieldtest"
return cell
}
}
extension HelloworkJobsEditJobViewController: UITableViewDelegate {
}
Any ideas on why it might be throwing this error would be greatly appreciated.
Upvotes: 0
Views: 81
Reputation: 3395
Use like this:
extension HelloworkJobsEditJobViewController: UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return 7
}
}
extension HelloworkJobsEditJobViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("\(#line): \(#function) \(indexPath.row)")
let cellIdentifier = "HelloworkJobsEditJobCell"
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? HelloworkJobsEditJobCell else {
fatalError("The dequeued cell is not an instance of HelloworkJobsEditJobCell.")
}
cell.cellLabel.text = "labeltest"
cell.cellTextField.text = "textfieldtest"
return cell
}
}
Upvotes: 2
Reputation: 100503
You must register the tableView with the cell custom class
tableView.register(UINib(nibName: "engineTableViewCell", bundle: nil), forCellReuseIdentifier:"cellID")
Or
tableView.register(engineTableViewCell.self, forCellReuseIdentifier: "cellID")
Upvotes: 3