UITableView cellForRowAtIndexPath never called

I have a UITableView as a UIViewController . The viewController interface is controlled through a storyboard. The delegate and data source are set in the viewController as needed.

I have the following code:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (updateType == Profile) { return 15; } else { return 6; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } 

The above two methods are called exactly as they should. A call to [self.tableview reloadData] results in repeated method calls. The incomprehensible part is that - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath never called. Someday.

The data source and delegate are set to code, where self.tableview is the IBOutlet for the UITableView in the storyboard:

 self.tableview.delegate = self; self.tableview.dataSource = self; 

Answer found

I use storyboards with auto layout. The problem was that the dimensions were set to wRegular hRegular, even though the rest of the storyboard was set up as WAny hAny. A simple switch made it work! Funny I know, but this is the answer nonetheless.

+5
source share
5 answers

There are several situations where delegate methods are not called. Therefore, first check your setup with the debugging tool to see if your setup is suitable, for example, checking for a table view, delegation, and data source in memory. If your data source is empty, the table view does not even try to invoke something that is not your business, since you are returning a specific number.

As a rule, these are just small mistakes made by programmers based on what I have done and seen before. So, double and triple code verification. And you better place your - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath .

WRITER ANSWER UPDATE: It turns out that the table view does not appear under some size class. That's why iOS won't even try, because it doesn't display at all. This is not a bug from Apple , and it can be detected by debugging the view.

+1
source

I use storyboards with auto layout. The problem was that the dimensions were set to wRegular hRegular, even though the rest of the storyboard was set up as WAny hAny. A simple switch made it work! Funny I know, but this is the answer nonetheless!

It works:
This works

It does not mean: This doesnt

It drove me crazy for too long, and I still don't quite understand the mechanics of why this works, but it is.

+1
source

Are you sure that your dataSource and delegate are set to the right classes? This is easy to do in IB, especially if you copy / paste. Put a breakpoint in your viewDidAppear method and then in a console call

 po self.tableView.dataSource 

to make sure it is installed at run time.

0
source

Are you sure that you are installing the table view socket on the interface builder ?, i.e. self.tableView != nil

0
source

In my particular case, the name numberOfRowsInSection did not cause anything until, for some reason, I turned the separator in the table view into one line (if it was set to none), then my heightForRowAtIndexPath was called later, when I executed some custom font size calculations with the wrong font name that caused it to lean back. Not sure if this helps anyone, but this is what happened to me.

0
source

All Articles