I'm following this tutorial because I want customized cells: https://www.youtube.com/watch?v=kYmZ-4l0Yy4
But it doesn't say how to add new cells so I just did this according to what I found here: How to insert new cell into UITableView in Swift
elements.append(["new data"])
tableView.beginUpdates()
tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: elements.count-1, inSection: 0)], withRowAnimation: .Automatic)
tableView.endUpdates()
I switched elements array from let to var because it gave me an error
And then the moment it gets to tableview.beginUpdates()
or tableview.reloadData()
it crashes giving me this error:
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
This is the rest of the code:
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cellActiveCastingSites") as!TableViewCell_CastingSite
cell.cellView.layer.cornerRadius = 15
cell.lblCastingName.text = elements[indexPath.row].0
cell.lblCastingWebsite.text = elements[indexPath.row].1
cell.CastingLogo.image = UIImage(named: "CastingLogo_" + elements[indexPath.row].0)
cell.CastingLogo.layer.cornerRadius = 20
cell.CastingLogo.layer.masksToBounds = true
cell.CastingLogo.layer.borderWidth = 1
cell.CastingLogo.layer.borderColor = UIColor.white.cgColor
return cell
}