I have a generic cell ItemCell
that can display any kind of item. The descendant of my Item
class is my Armor
class. I have a function inArmor
that overrides a function in Item
that returns an ItemCell
. However no matter what label, when I try to change the text value of one I get the error below. I can't even set a hard coded string. I also checked the ItemCell
class and it's .xib file and everything is linked. Is there something I'm missing? Let me know what code you would need to see as I have no idea where this issue is coming from.
fatal error: unexpectedly found nil while unwrapping an Optional value
CharacterTableView.swift
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tableView.register(UINib(nibName: "ItemCell", bundle: nil), forCellReuseIdentifier: "ItemCell")
switch sections[indexPath.section] {
case "Equipped":
return Character.inventory.equippedGear[indexPath.row].cell
case "Armor":
return Character.inventory.unequippedArmor[indexPath.row].cell
case "Weapons":
return Character.inventory.unequippedWeapons[indexPath.row].cell
case "Healing":
return Character.inventory.healingItems[indexPath.row].cell
default:
return ItemCell()
}
}
Armor.swift
override var cell: ItemCell {
let cell = ItemCell()
cell.name.text = "Name"
}
ItemCell.swift
class ItemCell: UITableViewCell {
//MARK: - IBOutlets
@IBOutlet weak var imageItem: UIImageView!
@IBOutlet weak var name: UILabel!
@IBOutlet weak var imageStat1: UIImageView!
@IBOutlet weak var labelStat1: UILabel!
@IBOutlet weak var imageStat2: UIImageView!
@IBOutlet weak var labelStat2: UILabel!
}