i'm currently facing an error in my swift file that nothing from the other threads on this subject solved.
I created a tableview thanks to my NewsTableViewController, I created a prototype for my custom cells that I identified as cell in the main storyboard. The Controller is alone and linked with no segue just as a prototype for display like this:
Controller on the right is my table view controller that bugs
But when I execute the application, when I click on the button that launches the piece of code that instantiate the NewsTableViewController, I have the error
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
The identifier of my prototype is good yet, so what is wrong? Here is the code of my NewsTableViewController :
class NewsTableViewController: UITableViewController {
var listOfDisplays = [String]()
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return listOfDisplays.count
}
func fetchEventsNames()
{
let fetchRequest:NSFetchRequest<Events> = Events.fetchRequest()
do {
let results = try DataBaseControler.getContext().fetch(fetchRequest)
for i in results as [Events]{ /* *dewraper les arguments (i.name)!*/
listOfDisplays.append(i.title!)
}
}
catch
{
print("errors\(error)")
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "cell"
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! NewsTableViewCell
cell.cellImage.image = UIImage(named: "rcbl.jpg")
cell.cellLabel.text = listOfDisplays[indexPath.row]
return(cell)
}
Here is also the code of my NewsTableViewCells :
class NewsTableViewCell: UITableViewCell {
@IBOutlet weak var cellLabel: UILabel!
@IBOutlet weak var cellImage: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
And then here is the piece of code where I call the constructor:
...
switch (names[row])
{
case "Actualités":
let destination = NewsTableViewController() // Your destination
destination.listOfDisplays = ["test1", "TEST2"]
navigationController?.pushViewController(destination, animated: true)...
What should I do to solve this problem ? Thank you in advance guys.