UITableView won't see custom UITableViewCell

I just made a second UITableViewCell class, and my table view won't see it when I try to instantiate it! Here's my cell class:


import UIKit

class RecordingCell: UITableViewCell {
    
    
    @IBOutlet var titleLabel: UILabel!
    var title : String = ""
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        title = titleLabel.text!
        
        titleAnimation()
        
    }
    
    
    
    func titleAnimation(){
        print ("starting the animation function")
        UIView.animate(withDuration: 1.5, delay: 1.5, options: .curveEaseInOut, animations: {
            
            self.titleLabel.text! = "Recording in Progress"
    
        }, completion: nil)
    }
}


It's super simple and just something I'm playing with. And here's how I'm filling the table view:


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if videoURLS.count == 0{
            selectButton.isEnabled = false
            let cell = tableView.dequeueReusableCell(withIdentifier: "emptyCell")
            return cell!
        }
            
        if tableView.numberOfRows(inSection: 0) == (videoURLS.count + 1){
            if indexPath.row == 0{
                let cell = self.tableView.dequeueReusableCell(withIdentifier: "recordingCell") as! RecordingCell
                return cell
            }
            if indexPath.row != 0{
                selectButton.isEnabled = true
                let cell = self.tableView.dequeueReusableCell(withIdentifier: "videoCell") as! VideoCell
                cell.videoURL = videoURLS[indexPath.row - 1]
                cell.parent = self
                cell.setViews()
                cell.setString()
                cell.setDate()
                cell.setTitle()
                cell.setSize()
                cell.setJpg()
                return cell
            }
        }
        else{
            selectButton.isEnabled = true
            let cell = self.tableView.dequeueReusableCell(withIdentifier: "videoCell") as! VideoCell
            cell.videoURL = videoURLS[indexPath.row]
            cell.parent = self
            cell.setViews()
            cell.setString()
            cell.setDate()
            cell.setTitle()
            cell.setSize()
            cell.setJpg()
            return cell
        }
    }


At line 11 it shows the error "Use of undeclared type RecordingCell." I've tried resetting the target in the cell class, but it still doesn't work.

Replies

VideoCell isn't declared any differently. I haven't registered the cell. This is actually the first time I've heard of registering a cell (yeah, I still got a lot to learn)

I don't have any other errors, only an alert message regarding another matter. I've tried cleaning the build several times to no avail, and what do you mean by putting an error code into RecordingCell?

what do you mean by putting an error code into RecordingCell?


Just modify your code to cause syntax error.

So just try to add, in viewDidLoad for instance,


tableView.register(RecordingCell.self, forCellReuseIdentifier: "recordingCell")

or, as you awake from nib


let nib = UINib(nibName: "recordingCell", bundle: nil)   // if recordingCell is Nib name as class 
tableView.register(nib, forCellReuseIdentifier: "recordingCell")


Can you please explain your thinking so I know what to look for? I'm not understanding your reasoning.

I registered the nib OK, but I still get the error Use of Undeclared type 'RecordingCell' in the cellForRowAt function.

Could you try to register the class directly ?


tableView.register(RecordingCell.self, forCellReuseIdentifier: "recordingCell")

I did, but I get the error Use of unresolved identifier 'RecordingCell'

That hard to understand.


Could you try to delete the RecordingCell file and recreate it ? With the same content.


Then do a Clean Build Folder.

My exact steps were delete the swift file, delete the reference in the storyboard, recreate the file, connect it in the storyboard, Cleaned Build Folder, and I still get the error.

Could you test to declare in the ViewController a var of type RecordingCell

var dummyCell: RecordingCell?


If OK here, what we would have to find, is what is the difference between VideoCell and RecordingCell.


In your situation, I would also try to make a copy of the project and remove VideoCell, just to see if the cause is to have 2 custom cells (even though I cannot figure out why !)

I just spotted a difference between the two. In the utilities tab, there's a text field entitled "On Demand Resource Tags." In VideoCell, I can set a tag. However, in RecordingCell it says "Only resources are taggable"!!!!! WTH

I'm just saying that you should better check if Xcode is compiling the source file.

Gotcha. Well, it does compile. I caused a simple error and it showed up.

What / where is the utilities tab ?


Could you make the same settings for RecordingCell than for VideoCell, for testing ?