-2

I am using a custom cell class in a tableview controller.

When I include a statement in the tableviewcontroller in cellForRowAtIndexPath NSLog(@"method called"): it does not seem to get called.

Is it possible that this method is not called when you have a custom cell?

Edit:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"cell for row at index path called");
    NSDictionary *item= [self.getItems objectAtIndex:indexPath.row];    
    //This sets place in storyboard VC
    IDTVCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.item = item;
    if (cell == nil) {
        cell = [[IDTVCell alloc] initWithStyle:UITableViewCellStyleDefault
                               reuseIdentifier:@"Cell"];
    }
    return cell;
    }
user1904273
  • 4,562
  • 11
  • 45
  • 96
  • Update your question with your actual `cellForRowAtIndexPath` method. Also make sure your data source methods are returning a non-zero number of rows. – rmaddy Oct 16 '15 at 23:56
  • The numberofrowsinsection method returns however many specified, i.e. return 1 returns 1. However, the cellforrowatindexpath does not seem to be called. – user1904273 Oct 17 '15 at 00:08
  • 1
    If you have non-zero sections and non-zero rows in the section then the `cellForRow...` method should be called. Have you verified that `numberOfRowsInSection:` is being called? – rmaddy Oct 17 '15 at 00:09
  • yes it is definitely called. Before viewdidload according to the order in the console. I was wondering if the custom cell affected this. – user1904273 Oct 17 '15 at 00:12
  • Is this a `UITableViewController` or a `UIViewController` with an added `UITableView`? If the latter, is the table view's frame set properly? How is `self.getItems` initialized? – rmaddy Oct 17 '15 at 00:15
  • the latter. getItems is an NSArray property in the .h file. It is assigned a value in viewDidLoad of an array. It is not initialized as I understand the compiler does this for properties. When you log it out in viewdidload it displays fine, but it returns null when logged to console from numberOfRowsInSeciton method. – user1904273 Oct 17 '15 at 00:21
  • Reload the table view after you populate `getItems`. – rmaddy Oct 17 '15 at 00:29

2 Answers2

0

cellForRowAtIndexPath is not called if no rows are returned.

-tableView:cellForRowAtIndexPath: is not getting called

That is what happened in my case.

It can also not get returned if you reload table on wrong thread and in certain other scenarios.

cellForRowAtIndexPath: not called

However, a custom cell per se does not cause this..

Community
  • 1
  • 1
user1904273
  • 4,562
  • 11
  • 45
  • 96
0

To answer your question - Yes, it is.

There could be n-number of reasons why cellForRowAtIndexPath: is not getting called. This may be because delegate / dataSource is not set or UITableView frame is not set... etc. etc.

You should easily find a solution with more online research and closure look at your code.

Abhinav
  • 37,684
  • 43
  • 191
  • 309