Custom view cell always has properties set to nil (UITableView)

Alexander Kozachenko

Table view cell in cellForRowAt alway has all properties set to nil

import UIKit

class TodoTableViewCell: UITableViewCell {
    @IBOutlet weak var label: UILabel!
}

class TodosViewController: UITableViewController {

    @IBOutlet var TodosTableView: UITableView!
    var projects = [Project]()
    var todos = [Todo]()

    override func viewDidLoad() {
        super.viewDidLoad()
        TodosTableView.delegate = self
        self.tableView.register(TodoTableViewCell.self, forCellReuseIdentifier: "TodoTableViewCell1")
        // data init
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "TodoTableViewCell1"
        var todo = projects[indexPath.section].todos[indexPath.row]
        guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? TodoTableViewCell else {
            fatalError("The dequeued cell is not an instance of MealTableViewCell.")
        }

        cell.label?.text = todo.text // cell.label is always nil
        return cell
    }
}

outlet class

identifier identifier

It seems like identical issue Custom table view cell: IBOutlet label is nil

What I tried to do: - restart Xcode - recreate outlet - clean project - recreate view cell from scratch like here https://www.ralfebert.de/ios-examples/uikit/uitableviewcontroller/custom-cells/

Please help, iOS development drives me nuts already.

Ash

You don't need to register the class in the tableview if you're using prototype cells in Interface Builder. Try removing the registration function from viewDidLoad. Incidentally you can also set dataSource and delegate in IB - much neater code-wise.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I uitableview the (cell = nil) always not call?

The last cell in UITableView always has the same height as the tallest cell in the table?

Casting custom annotation view always returning nil

Custom table view cell: IBOutlet label is nil

table view cell of custom class returning nil

How to filter contents of UITableView that has custom cell with Search Bar in Swift?

UITableView Custom Cell button selects other buttons out of the main view?

IBOutlet properties nil after custom view loaded from xib

how to set custom UILabel text on UITableView prototype cell

Why a first cell of UITableView custom cell is always called twice on action events in Xcode

Custom UITableView Cell Animation

Set that a cell always has the same value as another (actively)

Always keep cell on the top of uitableview

Found nil table view cell

Display a xib view into a UITableView Cell

Swift: IBoutlets are nil in Custom Cell

How to dynamically set constraints for a custom table view cell?

UITableView custom cell not displaying data

Not able to use Custom Cell with UITableView

Thousands of UITableViewCellSeperatorView in UITableView with custom cell

cell spacing in custom view cell

iOS Swift - Filtering contents of UITableView that has custom cell with Search Bar and Search Display

How to fire a callback after XML properties set in Android custom view?

How to get selected image and navigate to detail view from UITableViewCell (Custom cell) load by nib in UITableView

NSManagedObjects properties always nil with Quick-Nimble

Custom UITableCell has nil outlets

IOS 7 - Can't set font color of UITextView in custom UITableView cell

Unable to set constraints for custom UITableView Cell, created in xib as all data gets disappear on chage of size class

How to set the on UITableView cell width different from the selection of segment button in objc on one view using only one cell