Failed to obtain a cell from its DataSource
Your error suggests that cellForRowAtIndexPath
is returning nil
for some reason, and I'm guessing it's because you are failing to dequeue a reusable cell. If you want to confirm this, just set a breakpoint after your current dequeue call: I expect you'll find cell
is set to nil
.
If you're using modern Xcode templates where you get a prototype cell made for you, you should probably be using this instead:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
If you aren't using an Xcode template, use that line of code anyway then register your own re-use identifier like this:
[self.tableView registerClass:[UITableViewCell self] forCellReuseIdentifier:@"Cell"];
All being well that should resolve the problem. I wrote this up in more detail for Swift users.
failed to obtain a cell from its dataSource for swift4.2
Can you print weeklyWeather.count to see its number?
You may also peek the cell by setting a breakpoint at beginning of your tableView: cellForRowAt method.
Hope it helps.
UITableview: failed to obtain a cell from its dataSource
Cross check below check list:-
- it's because you are failing to dequeue a reusable cell.
- The problem is that your cellForRowAtIndexPath function is embedded in another function
- when you forgot to add the UITableViewDataSource and UITableViewDelegate protocols to the
ViewController declaration
.
class DataViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
failed to obtain a cell from its dataSource with swift 3
The error
failed to obtain a cell from its dataSource
occurs because the signature of cellForRowAtIndexPath
is wrong. In Swift 3 it's
(override) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
and use the convenience method
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for:indexPath)
which returns always a valid non-optional cell.
PS: You don't need to set datasource and delegate to self
because UITableViewController
does that implicitly
Failed to obtain a cell from its dataSource when loading UIView with Table
Based on the codes above you provided, I assume you are using a custom cell. You should register that resultsViewCell
Register that custom cell in viewDidLoad
[self.resultsTable registerNib:[UINib nibWithNibName:@"NAME_OF_YOUR_CELL_NIB" bundle:nil] forCellReuseIdentifier:@"resultsListCell"];
And I noticed that inside your animateResults method, you are assigning self to a delegate and datasource of resultsTable, shouldn't it be self.resultsTable or _resultsTable?
UITableView' failed to obtain a cell from its dataSource
Your method name for cellForRow is not correct.
Replace this line
func cellForRow(at indexPath: IndexPath) -> UITableViewCell?
{
with
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Related Topics
Change Language in the App Programmatically in iOS
Is It Considered a Private API to Use App-Prefs:Root
Property Not Working with Getter and Setter
How to Post String with Special Character and Thai Language Using Xml Parsing in Objective C
How to Test If a String Is Empty in Objective-C
How to Disable Back Swipe Gesture in Uinavigationcontroller on iOS 7
How to Create a Uiview Bounce Animation
Dynamically Changing Font Size of Uilabel
How to Play a Sound Using Swift
How to Initialize/Instantiate a Custom Uiview Class with a Xib File in Swift
How to Hide Keyboard in Swift on Pressing Return Key
How to Assign an Action for Uiimageview Object in Swift
Xcode - Ld: Library Not Found for -Lpods
Silent Push Notification in iOS 7 Does Not Work
Secitemadd and Secitemcopymatching Returns Error Code -34018 (Errsecmissingentitlement)
An App Id with Identifier '' Is Not Available. Please Enter a Different String
Uicollectionview Reloaddata Not Functioning Properly in iOS 7