cellForRowAtIndexPath nil during unit tests
Instantiate an actual UITableViewController
and this works fine.
unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
Have you set the Table Cell identifier to "Cell" in your storyboard?
Or have you set the class for the UITableViewController
to your class in that scene?
Difference between tableView.cellForRow(at:) and tableView.dataSource?tableView(tableView:cellForRowAt:)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
This method is used to generate or dequeue the cells as required by tableView. This is not the UITableView member method. Instead, it is a protocol method and another object, which will be a data source, will implement and return the value. So it will always return a cell whether we are unit testing or while debugging the app.
tableView.cellForRow(at:)
This method is not the generator method. It is a member method of UITableView as a utility method for eg. for getting selected row we use tableView.selectedRow. So it is supposed to return cell for any indexPath.
As we know UITableView doesn't create cells equal to rows drawn. Suppose you wanted to draw 100 rows then UITableView only create few extra cells apart from cells which are visible. So if you pass any indexPath which is not among the visible rows then practically that cell doesn't exist. Because tableview is waiting for you to scroll and reuse the unused cells. So whether you are doing unit testing or working on app it will always show nil for cells which are not visible.
Related Topics
Ambiguous Use of 'Filter' When Converting Project to Swift 4
Convert Time String into Date Swift
Nil Cannot Be Assigned to Type Avcapturedeviceinput
Swift: Binary Operator '==' Cannot Be Applied to Operands of Type "Protocol"
How to Get Reliable Timing for My Audio App
Answers by Crashlytics - Adding Custom Event
Swift: Parse, Query Date Field Based on Nsdate()
Swift: Using Member Constant as Default Value for Function Parameter
Nsurlconnection Throws After Updating to Swift 2.0
Swift Cannot Invoke '*' with an Argument List of Type '(Int, Int)'
Check Os Version Using Swift on MAC Os X
Xcode Failed to Resolve Dependency Firebase - Googleappmeasurement Does Not Match Requirement
How to Define a Variable in a Swift If Statement
"The Requested Snapshot Version Is Too Old." Error in Firestore
How Is Commoncrypto Used in Swift3
Make a Publisher from a Callback
How to Add Two Generic Values in Swift
Navigationlink Doesn't Work with New .Searchable Modifier on Swiftui 3.0