cellForRowAtIndexPath not called
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When cellForRowAt (or cellForRowAtIndexPath: in Objective-C) is not called, the table view has no cells to display. The most common causes are: numberOfRowsInSection returns 0 (empty data source), the dataSource delegate is not set, the table view has zero height due to Auto Layout constraints, or reloadData is called before the data is loaded. Debugging this requires checking the data source methods, the delegate connection, and the table view's frame in the view hierarchy.
Cause 1: numberOfRowsInSection Returns 0
If numberOfRowsInSection returns 0, UIKit never calls cellForRowAt. Add a breakpoint or print statement in numberOfRowsInSection to verify.
Cause 2: dataSource Not Set
Without a dataSource, UIKit does not know which object provides the cells. The table view appears empty with no errors.
Cause 3: Table View Has Zero Height
If the table view's height is 0 (due to missing or conflicting constraints), UIKit determines that zero cells fit on screen and never calls cellForRowAt. Use the Debug View Hierarchy in Xcode to inspect the table view's frame.
Cause 4: reloadData Called on Background Thread
UIKit is not thread-safe. Calling reloadData from a background thread may silently fail or cause intermittent issues where cellForRowAt is not called.
Cause 5: Cell Identifier Not Registered
An unregistered cell identifier causes a crash, not a silent failure. But if the crash is caught silently or occurs in a test environment, it can appear as if cellForRowAt is not called.
Cause 6: numberOfSections Returns 0
If you implement numberOfSections and it returns 0, no cells are displayed. If you do not implement it, UIKit defaults to 1 section.
Debugging Checklist
Common Pitfalls
- Data loads after
viewDidLoadbutreloadDatais never called: If data is fetched asynchronously, the initialnumberOfRowsInSectionreturns 0 (empty array). You must calltableView.reloadData()after the data arrives to trigger a new layout pass. - Table view hidden behind another view: If another view is placed on top of the table view or the table view's
isHiddenproperty istrue, cells are still created but not visible. Use Xcode's Debug View Hierarchy to check the view stack. - Using
UITableViewControllerbut overridingloadView:UITableViewControllerautomatically creates and configures aUITableViewwith itself as the data source. OverridingloadViewwithout callingsuperbreaks this automatic setup. - Forgetting
UITableViewDataSourceprotocol conformance: In Swift, the class must declare conformance toUITableViewDataSource. Without it, settingtableView.dataSource = selfcauses a compiler error (or a runtime crash if forced with casting). - Storyboard prototype cell identifier mismatch: If the cell identifier in
dequeueReusableCell(withIdentifier:)does not match the identifier set in the Storyboard's prototype cell, the table view crashes. Double-check the identifier spelling and case.
Summary
cellForRowAtis not called whennumberOfRowsInSectionreturns 0 — verify your data array is populated- Ensure
dataSourceis connected (in code or Interface Builder) - Check the table view has nonzero height via Auto Layout constraints
- Always call
reloadData()on the main thread after async data loads - Use print statements or breakpoints in
numberOfRowsInSectionto confirm it returns > 0 - Use Xcode's Debug View Hierarchy to verify the table view's frame and visibility
Related reading
- Center a button in a Linear layout
- Center content of UIScrollView when smaller
- Center NSTextAttachment image next to single line UILabel
- Center NSTextAttachment image next to single line UILabel
- cert-manager letsencrypt issuing invalid certs
- cert-manager letsencrypt order pending
- Center text vertically in a UITextView
- Centering a view in its superview using Visual Format Language
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.