uynva uynva - 1 year ago 62
iOS Question

TableView Cell Error - iOS/Swift

i have this error when run the tableView cellForRowAtIndexPath:

fatal error: unexpectedly found nil while unwrapping an Optional value

I do not understand, I have correctly assigned the identifier id but by mistake ..

This is my code:

When override the fun cellForRowAtIndexPath:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("CellDataflow") as UITableViewCell

cell.textLabel.text = "This is a title."
return cell

And here is where i call the view:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

….more code…
self.navigationController?.pushViewController(MainTVC(), animated: true)


N.B. => I call this way the new view because I have a custom cell, and I could not call it from the storyboard.


EDIT: The error in in the line:

let cell = tableView.dequeueReusableCellWithIdentifier("CellDataflow")
as UITableViewCell

Answer Source

Don't you also need the index path ?


let cell = tableView.dequeueReusableCellWithIdentifier("IDENTIFIER", forIndexPath: indexPath) as UITableViewCell
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download